i386-protos.h (x86_emit_floatuns): Declare.
[official-gcc.git] / gcc / ada / a-direio.adb
blobaef68f323ee7ce72ea1705d3c7688eac8157b33f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUNTIME COMPONENTS --
4 -- --
5 -- A D A . D I R E C T _ I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-1998 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This is the generic template for Direct_IO, i.e. the code that gets
36 -- duplicated. We absolutely minimize this code by either calling routines
37 -- in System.File_IO (for common file functions), or in System.Direct_IO
38 -- (for specialized Direct_IO functions)
40 with Interfaces.C_Streams; use Interfaces.C_Streams;
41 with System; use System;
42 with System.File_Control_Block;
43 with System.File_IO;
44 with System.Direct_IO;
45 with System.Storage_Elements;
46 with Unchecked_Conversion;
48 use type System.Direct_IO.Count;
50 package body Ada.Direct_IO is
52 Zeroes : System.Storage_Elements.Storage_Array :=
53 (1 .. System.Storage_Elements.Storage_Offset (Bytes) => 0);
54 -- Buffer used to fill out partial records.
56 package FCB renames System.File_Control_Block;
57 package FIO renames System.File_IO;
58 package DIO renames System.Direct_IO;
60 SU : constant := System.Storage_Unit;
62 subtype AP is FCB.AFCB_Ptr;
63 subtype FP is DIO.File_Type;
64 subtype DCount is DIO.Count;
65 subtype DPCount is DIO.Positive_Count;
67 function To_FCB is new Unchecked_Conversion (File_Mode, FCB.File_Mode);
68 function To_DIO is new Unchecked_Conversion (FCB.File_Mode, File_Mode);
70 -----------
71 -- Close --
72 -----------
74 procedure Close (File : in out File_Type) is
75 begin
76 FIO.Close (AP (File));
77 end Close;
79 ------------
80 -- Create --
81 ------------
83 procedure Create
84 (File : in out File_Type;
85 Mode : in File_Mode := Inout_File;
86 Name : in String := "";
87 Form : in String := "")
89 begin
90 DIO.Create (FP (File), To_FCB (Mode), Name, Form);
91 File.Bytes := Bytes;
92 end Create;
94 ------------
95 -- Delete --
96 ------------
98 procedure Delete (File : in out File_Type) is
99 begin
100 FIO.Delete (AP (File));
101 end Delete;
103 -----------------
104 -- End_Of_File --
105 -----------------
107 function End_Of_File (File : in File_Type) return Boolean is
108 begin
109 return DIO.End_Of_File (FP (File));
110 end End_Of_File;
112 ----------
113 -- Form --
114 ----------
116 function Form (File : in File_Type) return String is
117 begin
118 return FIO.Form (AP (File));
119 end Form;
121 -----------
122 -- Index --
123 -----------
125 function Index (File : in File_Type) return Positive_Count is
126 begin
127 return Positive_Count (DIO.Index (FP (File)));
128 end Index;
130 -------------
131 -- Is_Open --
132 -------------
134 function Is_Open (File : in File_Type) return Boolean is
135 begin
136 return FIO.Is_Open (AP (File));
137 end Is_Open;
139 ----------
140 -- Mode --
141 ----------
143 function Mode (File : in File_Type) return File_Mode is
144 begin
145 return To_DIO (FIO.Mode (AP (File)));
146 end Mode;
148 ----------
149 -- Name --
150 ----------
152 function Name (File : in File_Type) return String is
153 begin
154 return FIO.Name (AP (File));
155 end Name;
157 ----------
158 -- Open --
159 ----------
161 procedure Open
162 (File : in out File_Type;
163 Mode : in File_Mode;
164 Name : in String;
165 Form : in String := "")
167 begin
168 DIO.Open (FP (File), To_FCB (Mode), Name, Form);
169 File.Bytes := Bytes;
170 end Open;
172 ----------
173 -- Read --
174 ----------
176 procedure Read
177 (File : in File_Type;
178 Item : out Element_Type;
179 From : in Positive_Count)
181 begin
182 -- For a non-constrained variant record type, we read into an
183 -- intermediate buffer, since we may have the case of discriminated
184 -- records where a discriminant check is required, and we may need
185 -- to assign only part of the record buffer originally written
187 if not Element_Type'Constrained then
188 declare
189 Buf : Element_Type;
191 begin
192 DIO.Read (FP (File), Buf'Address, Bytes, DPCount (From));
193 Item := Buf;
194 end;
196 -- In the normal case, we can read straight into the buffer
198 else
199 DIO.Read (FP (File), Item'Address, Bytes, DPCount (From));
200 end if;
201 end Read;
203 procedure Read (File : in File_Type; Item : out Element_Type) is
204 begin
205 -- Same processing for unconstrained case as above
207 if not Element_Type'Constrained then
208 declare
209 Buf : Element_Type;
211 begin
212 DIO.Read (FP (File), Buf'Address, Bytes);
213 Item := Buf;
214 end;
216 else
217 DIO.Read (FP (File), Item'Address, Bytes);
218 end if;
219 end Read;
221 -----------
222 -- Reset --
223 -----------
225 procedure Reset (File : in out File_Type; Mode : in File_Mode) is
226 begin
227 DIO.Reset (FP (File), To_FCB (Mode));
228 end Reset;
230 procedure Reset (File : in out File_Type) is
231 begin
232 DIO.Reset (FP (File));
233 end Reset;
235 ---------------
236 -- Set_Index --
237 ---------------
239 procedure Set_Index (File : in File_Type; To : in Positive_Count) is
240 begin
241 DIO.Set_Index (FP (File), DPCount (To));
242 end Set_Index;
244 ----------
245 -- Size --
246 ----------
248 function Size (File : in File_Type) return Count is
249 begin
250 return Count (DIO.Size (FP (File)));
251 end Size;
253 -----------
254 -- Write --
255 -----------
257 procedure Write
258 (File : in File_Type;
259 Item : in Element_Type;
260 To : in Positive_Count)
262 begin
263 DIO.Set_Index (FP (File), DPCount (To));
264 DIO.Write (FP (File), Item'Address, Item'Size / SU, Zeroes);
265 end Write;
267 procedure Write (File : in File_Type; Item : in Element_Type) is
268 begin
269 DIO.Write (FP (File), Item'Address, Item'Size / SU, Zeroes);
270 end Write;
272 end Ada.Direct_IO;