comp.lang.ada
 help / color / mirror / Atom feed
* Re: File locking on POSIX systems
       [not found] <vhi1zcoywll.fsf@grotte.ifi.uio.no>
@ 1999-08-28  0:00 ` jerry
  0 siblings, 0 replies; only message in thread
From: jerry @ 1999-08-28  0:00 UTC (permalink / raw)


Jan Kroken <jankr@nntp.ifi.uio.no> 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.

<snip>

: 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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-08-28  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <vhi1zcoywll.fsf@grotte.ifi.uio.no>
1999-08-28  0:00 ` File locking on POSIX systems jerry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox