From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ce73aa5d06b3160,start X-Google-Attributes: gid103376,public From: jerry@jvdsys.stuyts.nl Subject: Re: File locking on POSIX systems Date: 1999/08/28 Message-ID: #1/1 X-Deja-AN: 518336322 Sender: jerry@stuyts.nl (Jerry van Dijk) References: Organization: * JerryWare HQ *, Leiden, Holland User-Agent: tin/pre-1.4-980226 (UNIX) (Linux/2.2.11 (i586)) Newsgroups: comp.lang.ada Date: 1999-08-28T00:00:00+00:00 List-Id: Jan Kroken wrote: : lock a file : read the content of the file : write to the file : unlock the file : I'm using Ada.Text_IO.* to read/write. : But a friend argues that I should rather use Any reason as to why ? It would depend on your application, its data, C library and OS you are using. : To do the latter, I have to pass an open file descriptor between Ada : and C. Is there any safe and portable way I could get that to work? Yes, use the facilities from the Interfaces.C package. But since you are not using a POSIX binding, any implementation involving calls to the C library is inherentely platform bound and thus in principle none-portable. (assuming that all C libraries are created equal, or at least support POSIX, is not going to work) Given the different ways in which file locking is inplemented on different operating systems, the posibility of your program being portable is not very high. For example, if your program was written on Linux and someone wants it to run on NT, its a no-go. Another approach that I have used in this situation is to store/retrieve my data using the gdbm library. Open a database as a writer, and the gdbm library will automatically open the database with an exclusive lock. You need to add some simple code to interface to gdbm, but that is not very much work. And gdbm runs on just about anything. Of course, if you happen to process system log file or some such, that isn't going to be of much use. Another approach is to forego Text_IO completely and use the C library functions directly from Ada. Although this will be totally unportable on the C side, of course. -- -- Jerry van Dijk | email: jdijk@acm.org -- Team Ada | web: http://stad.dsl.nl/~jvandyk -- Leiden, Holland | Paris, France