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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Exclusive file access Date: Sat, 29 Aug 2015 09:05:48 +0200 Organization: cbb software GmbH Message-ID: References: <75714e3f-c047-413d-9aa5-3ff423167863@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: j5pd6+YW13W3aOTpCbIMJw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:27634 Date: 2015-08-29T09:05:48+02:00 List-Id: On Fri, 28 Aug 2015 10:40:45 -0700 (PDT), ahlan@marriott.org wrote: > Now that we have abandoned OA in favour of Gnat and because Gnat provides > a mechanism to open files with non-ascii names I had hoped that we could > abandon all this fancy windows stuff and use plain Ada. I doubt that. Windows "non-ascii" file names are UTF-16. The only consistent way to have them would be Wide_Wide_Text_IO with names in Wide_Wide_String internally recoded to UTF-16. Does GNAT this? I didn't look at the implementation, but I bet it does not. Then how would you do I/O if the content is not Wide_Wide_String? > The hope was that it would also be platform independent. It is Ada standard which prevents reasonable and portable operations with Unicode file names. You cannot do anything about that. (I use GIO instead of Ada.Directories when I have to deal with localized file names.) > From what everyone has written it seems that this is not possible. Not if the language I/O abstraction layer does not have this capability. Ada's does not. > It seems that I should somehow lock the file once it has been opened by Ada. Windows locks the file if the sharing mode is 0. See https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx I don't know what flag GNAT ultimately uses, or if it goes through a POSIX layer, what the later does. Possibly it ends up with FILE_SHARE_READ. > Has anyone any suggestions how best to do that? Use Win32Ada. > Ie How does one write a GNAT Ada program for windows that has exclusive > access when opened for write. By using OS API. If you have do deal with many different OSes create an abstraction layer and have an implementations of per OS. > Surely this must be a common requirement? It is not. Concurrently accessed files presume some persistency being implemented. It is very uncommon to be done at the file level. DBMS are for this. When single-file persistency is used it is most of the time an embedded target where you need not to care about concurrent access. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de