]>
Commit | Line | Data |
---|---|---|
d23b8f57 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT RUN-TIME COMPONENTS -- | |
4 | -- -- | |
5 | -- A D A . D I R E C T _ I O -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
4b490c1e | 9 | -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- |
d23b8f57 RK |
10 | -- -- |
11 | -- This specification is derived from the Ada Reference Manual for use with -- | |
12 | -- GNAT. The copyright notice above, and the license provisions that follow -- | |
13 | -- apply solely to the contents of the part following the private keyword. -- | |
14 | -- -- | |
15 | -- GNAT is free software; you can redistribute it and/or modify it under -- | |
16 | -- terms of the GNU General Public License as published by the Free Soft- -- | |
748086b7 | 17 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
d23b8f57 RK |
18 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
19 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- | |
748086b7 JJ |
20 | -- or FITNESS FOR A PARTICULAR PURPOSE. -- |
21 | -- -- | |
22 | -- As a special exception under Section 7 of GPL version 3, you are granted -- | |
23 | -- additional permissions described in the GCC Runtime Library Exception, -- | |
24 | -- version 3.1, as published by the Free Software Foundation. -- | |
25 | -- -- | |
26 | -- You should have received a copy of the GNU General Public License and -- | |
27 | -- a copy of the GCC Runtime Library Exception along with this program; -- | |
28 | -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- | |
29 | -- <http://www.gnu.org/licenses/>. -- | |
d23b8f57 RK |
30 | -- -- |
31 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 32 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
d23b8f57 RK |
33 | -- -- |
34 | ------------------------------------------------------------------------------ | |
35 | ||
d23b8f57 RK |
36 | with Ada.IO_Exceptions; |
37 | with System.Direct_IO; | |
38 | with Interfaces.C_Streams; | |
39 | ||
40 | generic | |
41 | type Element_Type is private; | |
42 | ||
43 | package Ada.Direct_IO is | |
44 | ||
523456db AC |
45 | pragma Compile_Time_Warning |
46 | (Element_Type'Has_Access_Values, | |
bfc8aa81 | 47 | "Element_Type for Direct_IO instance has access values"); |
523456db | 48 | |
efde9617 RD |
49 | pragma Compile_Time_Warning |
50 | (Element_Type'Has_Tagged_Values, | |
51 | "Element_Type for Direct_IO instance has tagged values"); | |
52 | ||
210fef2d | 53 | type File_Type is limited private with Default_Initial_Condition; |
d23b8f57 RK |
54 | |
55 | type File_Mode is (In_File, Inout_File, Out_File); | |
56 | ||
57 | -- The following representation clause allows the use of unchecked | |
58 | -- conversion for rapid translation between the File_Mode type | |
59 | -- used in this package and System.File_IO. | |
60 | ||
61 | for File_Mode use | |
523456db AC |
62 | (In_File => 0, -- System.File_IO.File_Mode'Pos (In_File) |
63 | Inout_File => 1, -- System.File_IO.File_Mode'Pos (Inout_File); | |
64 | Out_File => 2); -- System.File_IO.File_Mode'Pos (Out_File) | |
d23b8f57 RK |
65 | |
66 | type Count is range 0 .. System.Direct_IO.Count'Last; | |
67 | ||
68 | subtype Positive_Count is Count range 1 .. Count'Last; | |
69 | ||
70 | --------------------- | |
71 | -- File Management -- | |
72 | --------------------- | |
73 | ||
74 | procedure Create | |
75 | (File : in out File_Type; | |
0ae9f22f RD |
76 | Mode : File_Mode := Inout_File; |
77 | Name : String := ""; | |
78 | Form : String := ""); | |
d23b8f57 RK |
79 | |
80 | procedure Open | |
81 | (File : in out File_Type; | |
0ae9f22f RD |
82 | Mode : File_Mode; |
83 | Name : String; | |
84 | Form : String := ""); | |
d23b8f57 RK |
85 | |
86 | procedure Close (File : in out File_Type); | |
87 | procedure Delete (File : in out File_Type); | |
0ae9f22f | 88 | procedure Reset (File : in out File_Type; Mode : File_Mode); |
d23b8f57 RK |
89 | procedure Reset (File : in out File_Type); |
90 | ||
0ae9f22f RD |
91 | function Mode (File : File_Type) return File_Mode; |
92 | function Name (File : File_Type) return String; | |
93 | function Form (File : File_Type) return String; | |
d23b8f57 | 94 | |
0ae9f22f | 95 | function Is_Open (File : File_Type) return Boolean; |
d23b8f57 | 96 | |
f6c5454e PO |
97 | procedure Flush (File : File_Type); |
98 | ||
d23b8f57 RK |
99 | --------------------------------- |
100 | -- Input and Output Operations -- | |
101 | --------------------------------- | |
102 | ||
103 | procedure Read | |
0ae9f22f | 104 | (File : File_Type; |
d23b8f57 | 105 | Item : out Element_Type; |
0ae9f22f | 106 | From : Positive_Count); |
d23b8f57 RK |
107 | |
108 | procedure Read | |
0ae9f22f | 109 | (File : File_Type; |
d23b8f57 RK |
110 | Item : out Element_Type); |
111 | ||
112 | procedure Write | |
0ae9f22f RD |
113 | (File : File_Type; |
114 | Item : Element_Type; | |
115 | To : Positive_Count); | |
d23b8f57 RK |
116 | |
117 | procedure Write | |
0ae9f22f RD |
118 | (File : File_Type; |
119 | Item : Element_Type); | |
d23b8f57 | 120 | |
0ae9f22f | 121 | procedure Set_Index (File : File_Type; To : Positive_Count); |
d23b8f57 | 122 | |
0ae9f22f RD |
123 | function Index (File : File_Type) return Positive_Count; |
124 | function Size (File : File_Type) return Count; | |
d23b8f57 | 125 | |
0ae9f22f | 126 | function End_Of_File (File : File_Type) return Boolean; |
d23b8f57 RK |
127 | |
128 | ---------------- | |
129 | -- Exceptions -- | |
130 | ---------------- | |
131 | ||
132 | Status_Error : exception renames IO_Exceptions.Status_Error; | |
133 | Mode_Error : exception renames IO_Exceptions.Mode_Error; | |
134 | Name_Error : exception renames IO_Exceptions.Name_Error; | |
135 | Use_Error : exception renames IO_Exceptions.Use_Error; | |
136 | Device_Error : exception renames IO_Exceptions.Device_Error; | |
137 | End_Error : exception renames IO_Exceptions.End_Error; | |
138 | Data_Error : exception renames IO_Exceptions.Data_Error; | |
139 | ||
140 | private | |
e2baae4e TQ |
141 | |
142 | -- The following procedures have a File_Type formal of mode IN OUT because | |
143 | -- they may close the original file. The Close operation may raise an | |
144 | -- exception, but in that case we want any assignment to the formal to | |
145 | -- be effective anyway, so it must be passed by reference (or the caller | |
146 | -- will be left with a dangling pointer). | |
147 | ||
148 | pragma Export_Procedure | |
149 | (Internal => Close, | |
150 | External => "", | |
151 | Mechanism => Reference); | |
152 | pragma Export_Procedure | |
153 | (Internal => Delete, | |
154 | External => "", | |
155 | Mechanism => Reference); | |
156 | pragma Export_Procedure | |
157 | (Internal => Reset, | |
158 | External => "", | |
159 | Parameter_Types => (File_Type), | |
160 | Mechanism => Reference); | |
161 | pragma Export_Procedure | |
162 | (Internal => Reset, | |
163 | External => "", | |
164 | Parameter_Types => (File_Type, File_Mode), | |
165 | Mechanism => (File => Reference)); | |
166 | ||
d23b8f57 RK |
167 | type File_Type is new System.Direct_IO.File_Type; |
168 | ||
169 | Bytes : constant Interfaces.C_Streams.size_t := | |
2db15b1d AC |
170 | Interfaces.C_Streams.size_t'Max |
171 | (1, Element_Type'Max_Size_In_Storage_Elements); | |
172 | -- Size of an element in storage units. The Max operation here is to ensure | |
173 | -- that we allocate a single byte for zero-sized elements. It's a bit weird | |
174 | -- to instantiate Direct_IO with zero sized elements, but it is legal and | |
d8221f45 | 175 | -- this adjustment ensures that we don't get anomalous behavior. |
d23b8f57 RK |
176 | |
177 | pragma Inline (Close); | |
178 | pragma Inline (Create); | |
179 | pragma Inline (Delete); | |
180 | pragma Inline (End_Of_File); | |
181 | pragma Inline (Form); | |
182 | pragma Inline (Index); | |
183 | pragma Inline (Is_Open); | |
184 | pragma Inline (Mode); | |
185 | pragma Inline (Name); | |
186 | pragma Inline (Open); | |
187 | pragma Inline (Read); | |
188 | pragma Inline (Reset); | |
189 | pragma Inline (Set_Index); | |
190 | pragma Inline (Size); | |
191 | pragma Inline (Write); | |
192 | ||
193 | end Ada.Direct_IO; |