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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Exclusive file access Date: Tue, 1 Sep 2015 15:36:43 -0500 Organization: JSA Research & Innovation Message-ID: References: NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1441139804 19053 24.196.82.226 (1 Sep 2015 20:36:44 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 1 Sep 2015 20:36:44 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:27682 Date: 2015-09-01T15:36:43-05:00 List-Id: "Simon Wright" wrote in message news:lyh9nexjed.fsf@pushface.org... > ahlan@marriott.org writes: > >> Bruce B. tells me that there are routines in the package Directories >> that can be used to check if the file is already open. However that >> wouldn't be a full solution because there would be nothing to stop any >> other program from opening the file and messing with it. However it >> would be a start. If the file was already opened (by some other >> process) then I could avoid opening it. Unfortunately I couldn't find >> any such routine in Ada.Directories. Am I going blind? ... > I think you are rather out of luck. I can see how it might be done on OS > X [open(2) with O_EXLOCK, then write(2)]. It's trivial to do on Windows, one just needs to open the file with the correct sharing flags (and I think that the correct flag is the default). Sharing is a built-in part of the file descriptor in Windows; there's no need for separate locking so long as you want to do full-file exclusion (as in this case). Typically, those sharing flags are made available through a Form parameter. Janus/Ada uses 'R' and 'W' to indicate read and write sharing (respectively). (So a form of "RW" opens a file allowing read and write sharing, while opening a file with "" - the default - opens it for exclusive access.) But this will be different on different compilers, plus it's specific to Windows. Randy.