2015-05-20 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / ada / s-direio.ads
blob4a60ee72e8e93f4d6a5d4bb88590096ed991635d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . D I R E C T _ I O --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This package contains the declaration of the control block used for
33 -- Direct_IO. This must be declared at the outer library level. It also
34 -- contains code that is shared between instances of Direct_IO.
36 with Interfaces.C_Streams;
37 with Ada.Streams;
38 with System.File_Control_Block;
39 with System.Storage_Elements;
41 package System.Direct_IO is
43 package FCB renames System.File_Control_Block;
45 type Operation is (Op_Read, Op_Write, Op_Other);
46 -- Type used to record last operation (to optimize sequential operations)
48 subtype Count is Interfaces.C_Streams.int64;
49 -- The Count type in each instantiation is derived from this type
51 subtype Positive_Count is Count range 1 .. Count'Last;
53 type Direct_AFCB is new FCB.AFCB with record
54 Index : Count := 1;
55 -- Current Index value
57 Bytes : Interfaces.C_Streams.size_t;
58 -- Length of item in bytes (set from inside generic template)
60 Last_Op : Operation := Op_Other;
61 -- Last operation performed on file, used to avoid unnecessary
62 -- repositioning between successive read or write operations.
63 end record;
65 function AFCB_Allocate (Control_Block : Direct_AFCB) return FCB.AFCB_Ptr;
67 procedure AFCB_Close (File : not null access Direct_AFCB);
68 procedure AFCB_Free (File : not null access Direct_AFCB);
70 procedure Read
71 (File : in out Direct_AFCB;
72 Item : out Ada.Streams.Stream_Element_Array;
73 Last : out Ada.Streams.Stream_Element_Offset);
74 -- Required overriding of Read, not actually used for Direct_IO
76 procedure Write
77 (File : in out Direct_AFCB;
78 Item : Ada.Streams.Stream_Element_Array);
79 -- Required overriding of Write, not actually used for Direct_IO
81 type File_Type is access all Direct_AFCB;
82 -- File_Type in individual instantiations is derived from this type
84 procedure Create
85 (File : in out File_Type;
86 Mode : FCB.File_Mode := FCB.Inout_File;
87 Name : String := "";
88 Form : String := "");
90 function End_Of_File (File : File_Type) return Boolean;
92 function Index (File : File_Type) return Positive_Count;
94 procedure Open
95 (File : in out File_Type;
96 Mode : FCB.File_Mode;
97 Name : String;
98 Form : String := "");
100 procedure Read
101 (File : File_Type;
102 Item : System.Address;
103 Size : Interfaces.C_Streams.size_t;
104 From : Positive_Count);
106 procedure Read
107 (File : File_Type;
108 Item : System.Address;
109 Size : Interfaces.C_Streams.size_t);
111 procedure Reset (File : in out File_Type; Mode : FCB.File_Mode);
112 procedure Reset (File : in out File_Type);
114 procedure Set_Index (File : File_Type; To : Positive_Count);
116 function Size (File : File_Type) return Count;
118 procedure Write
119 (File : File_Type;
120 Item : System.Address;
121 Size : Interfaces.C_Streams.size_t;
122 Zeroes : System.Storage_Elements.Storage_Array);
123 -- Note: Zeroes is the buffer of zeroes used to fill out partial records
125 -- The following procedures have a File_Type formal of mode IN OUT because
126 -- they may close the original file. The Close operation may raise an
127 -- exception, but in that case we want any assignment to the formal to
128 -- be effective anyway, so it must be passed by reference (or the caller
129 -- will be left with a dangling pointer).
131 pragma Export_Procedure
132 (Internal => Reset,
133 External => "",
134 Parameter_Types => (File_Type),
135 Mechanism => Reference);
136 pragma Export_Procedure
137 (Internal => Reset,
138 External => "",
139 Parameter_Types => (File_Type, FCB.File_Mode),
140 Mechanism => (File => Reference));
142 end System.Direct_IO;