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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dfd038701140e897,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!57g2000hsv.googlegroups.com!not-for-mail From: msimonides@power.com.pl Newsgroups: comp.lang.ada Subject: Mixing reading and writing to a text file Date: Thu, 02 Aug 2007 00:43:26 -0700 Organization: http://groups.google.com Message-ID: <1186040606.842876.191850@57g2000hsv.googlegroups.com> NNTP-Posting-Host: 62.111.211.178 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" X-Trace: posting.google.com 1186040607 16288 127.0.0.1 (2 Aug 2007 07:43:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 2 Aug 2007 07:43:27 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.22 (X11; Linux i686; U; en),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 57g2000hsv.googlegroups.com; posting-host=62.111.211.178; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1327 Date: 2007-08-02T00:43:26-07:00 List-Id: I'm facing a situation, where I need to access a text file for both input and output. This file is used for storing a sequence of different records (of various lengths - it's not possible to define the upper bound) defining operations that need to be performed. Some errors could occur and the processing might be aborted. In this case it is crucial to store state of the processing (in the simplest case only the number of the last record processed) must be saved, so that it may be resumed later. The task seems simple as I have complete control over the file format. I'd rather use human-readable format but a binary one is also acceptable. The problem I have is with writing the state information back to file. Ada.Text_IO and Ada.Streams.Stream_IO only allow opening file for input or for output. In the latter case the file is being truncated (as far as I understand the ARM). Currently I'm mixing Text_IO and Direct_IO: Text_IO is used for reading and writing the file initially and Direct_IO is used to overwrite the first dozen characters that specify state. This approach has many deficiencies, of course, like reopening the file in different mode (which might fail due to permissions). My first question is: can I freely mix Text_IO and Direct_IO at all? The main question is: How should I approach this problem? I've considered using Ada/POSIX binding like Florist but I'm not sure whether it would be portable to Windows (currently there's no such requirement in our project, but I don't want to close this path). -- Marcin Simonides