comp.lang.ada
 help / color / mirror / Atom feed
* Opening a file vs. creating if not yet exists
@ 2008-08-18 15:03 Maciej Sobczak
  2008-08-19 12:36 ` Rob Norris
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Maciej Sobczak @ 2008-08-18 15:03 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-08-21 21:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-18 15:03 Opening a file vs. creating if not yet exists Maciej Sobczak
2008-08-19 12:36 ` 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

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