comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Opening a file vs. creating if not yet exists
Date: Mon, 18 Aug 2008 08:03:29 -0700 (PDT)
Date: 2008-08-18T08:03:29-07:00	[thread overview]
Message-ID: <af68d80f-0f42-4524-a963-80c91b427ad9@k7g2000hsd.googlegroups.com> (raw)

Hi,

The Open procedure for opening files expects the given external file
to already exist (otherwise the Name_Error is signalled).

The Create procedure truncates the file no matter what, even if the
mode for opening a file is Append_File.

I find this a bit annoying for example with log files, where the
natural scheme should be:
- if the file exists, open and append to it
- if the file does not exist, create it and append to it

What is the recommended way to deal with this?

begin
   Open (File, Append_File, "file.txt");
exception
   when Name_Error =>
      Create (File, Append_File, "file.txt");
end;

Is the above idiomatic (ie. well understood and accepted as common
practice)?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



             reply	other threads:[~2008-08-18 15:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-18 15:03 Maciej Sobczak [this message]
2008-08-19 12:36 ` Opening a file vs. creating if not yet exists Rob Norris
2008-08-19 12:58 ` amado.alves
2008-08-19 14:23 ` Jacob Sparre Andersen
2008-08-19 14:58   ` Maciej Sobczak
2008-08-21 15:41     ` Martin Krischik
2008-08-21 21:06       ` Maciej Sobczak
2008-08-21 15:42     ` Martin Krischik
replies disabled

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