agpl_1.0.0_b5da3320/src/agpl-safe_file.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 

--  Facilities for saving/loading from a file in a way that it doesn't
--  overwrite the previous version.
--  When opening for writing, a temporary is used. After completion, the
--  original file is removed and the temporary renamed.
--  When opening for reading, regular filename is tried. If missing, a check
--  for a temporary is made, and if it exists, it is renamed to the regular
--  name and opened. If neither regular and temporary exists, error.

with Ada.Streams.Stream_IO;
use  Ada.Streams;
use  Ada;

package Agpl.Safe_file is

   --  pragma Elaborate_Body;

   File_Not_Found : exception;

   ------------------------------------------------------------------------
   -- Exists_for_reading                                                 --
   ------------------------------------------------------------------------
   function Exists_for_reading (Name : in String) return Boolean;

   ------------------------------------------------------------------------
   -- Get_Real_Name                                                      --
   ------------------------------------------------------------------------
   --  Gets the real name found (i.e. the supplied or the backup one
   --  May raise File_Not_Found
   function Get_Real_Name (Name : in String) return String;

   ------------------------------------------------------------------------
   -- Open                                                               --
   ------------------------------------------------------------------------
   procedure Open (
      File : in out Stream_IO.File_type;
      Mode : in     Stream_IO.File_mode;
      Name : in     String := "";
      Form : in     String := "");

   ------------------------------------------------------------------------
   -- Close                                                              --
   ------------------------------------------------------------------------
   procedure Close (File : in out Stream_IO.File_type);

end Agpl.Safe_file;