Add hppa-openbsd target
[official-gcc.git] / gcc / ada / a-ststio.ads
blob14f61f5be6fcba73a7a24e685c15efc27a133e64
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R E A M S . S T R E A M _ I O --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
12 -- This specification is derived from the Ada Reference Manual for use with --
13 -- GNAT. The copyright notice above, and the license provisions that follow --
14 -- apply solely to the contents of the part following the private keyword. --
15 -- --
16 -- GNAT is free software; you can redistribute it and/or modify it under --
17 -- terms of the GNU General Public License as published by the Free Soft- --
18 -- ware Foundation; either version 2, or (at your option) any later ver- --
19 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
20 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
21 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
22 -- for more details. You should have received a copy of the GNU General --
23 -- Public License distributed with GNAT; see file COPYING. If not, write --
24 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
25 -- MA 02111-1307, USA. --
26 -- --
27 -- As a special exception, if other files instantiate generics from this --
28 -- unit, or you link this unit with other files to produce an executable, --
29 -- this unit does not by itself cause the resulting executable to be --
30 -- covered by the GNU General Public License. This exception does not --
31 -- however invalidate any other reasons why the executable file might be --
32 -- covered by the GNU Public License. --
33 -- --
34 -- GNAT was originally developed by the GNAT team at New York University. --
35 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
36 -- --
37 ------------------------------------------------------------------------------
39 with Ada.IO_Exceptions;
40 with System.File_Control_Block;
42 package Ada.Streams.Stream_IO is
44 type Stream_Access is access all Root_Stream_Type'Class;
46 type File_Type is limited private;
48 type File_Mode is (In_File, Out_File, Append_File);
50 -- The following representation clause allows the use of unchecked
51 -- conversion for rapid translation between the File_Mode type
52 -- used in this package and System.File_IO.
54 for File_Mode use
55 (In_File => 0, -- System.FIle_IO.File_Mode'Pos (In_File)
56 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
57 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
59 type Count is new Stream_Element_Offset
60 range 0 .. Stream_Element_Offset'Last;
62 subtype Positive_Count is Count range 1 .. Count'Last;
63 -- Index into file, in stream elements
65 ---------------------
66 -- File Management --
67 ---------------------
69 procedure Create
70 (File : in out File_Type;
71 Mode : in File_Mode := Out_File;
72 Name : in String := "";
73 Form : in String := "");
75 procedure Open
76 (File : in out File_Type;
77 Mode : in File_Mode;
78 Name : in String;
79 Form : in String := "");
81 procedure Close (File : in out File_Type);
82 procedure Delete (File : in out File_Type);
83 procedure Reset (File : in out File_Type; Mode : in File_Mode);
84 procedure Reset (File : in out File_Type);
86 function Mode (File : in File_Type) return File_Mode;
87 function Name (File : in File_Type) return String;
88 function Form (File : in File_Type) return String;
90 function Is_Open (File : in File_Type) return Boolean;
91 function End_Of_File (File : in File_Type) return Boolean;
93 function Stream (File : in File_Type) return Stream_Access;
95 -----------------------------
96 -- Input-Output Operations --
97 -----------------------------
99 procedure Read
100 (File : in File_Type;
101 Item : out Stream_Element_Array;
102 Last : out Stream_Element_Offset;
103 From : in Positive_Count);
105 procedure Read
106 (File : in File_Type;
107 Item : out Stream_Element_Array;
108 Last : out Stream_Element_Offset);
110 procedure Write
111 (File : in File_Type;
112 Item : in Stream_Element_Array;
113 To : in Positive_Count);
115 procedure Write
116 (File : in File_Type;
117 Item : in Stream_Element_Array);
119 ----------------------------------------
120 -- Operations on Position within File --
121 ----------------------------------------
123 procedure Set_Index (File : in File_Type; To : in Positive_Count);
125 function Index (File : in File_Type) return Positive_Count;
126 function Size (File : in File_Type) return Count;
128 procedure Set_Mode (File : in out File_Type; Mode : in File_Mode);
130 -- Note: The parameter file is IN OUT in the RM, but this is clearly
131 -- an oversight, and was intended to be IN, see AI95-00057.
133 procedure Flush (File : File_Type);
135 ----------------
136 -- Exceptions --
137 ----------------
139 Status_Error : exception renames IO_Exceptions.Status_Error;
140 Mode_Error : exception renames IO_Exceptions.Mode_Error;
141 Name_Error : exception renames IO_Exceptions.Name_Error;
142 Use_Error : exception renames IO_Exceptions.Use_Error;
143 Device_Error : exception renames IO_Exceptions.Device_Error;
144 End_Error : exception renames IO_Exceptions.End_Error;
145 Data_Error : exception renames IO_Exceptions.Data_Error;
147 private
148 package FCB renames System.File_Control_Block;
150 -----------------------------
151 -- Stream_IO Control Block --
152 -----------------------------
154 type Operation is (Op_Read, Op_Write, Op_Other);
155 -- Type used to record last operation (to optimize sequential operations)
157 type Stream_AFCB is new FCB.AFCB with record
158 Index : Count := 1;
159 -- Current Index value
161 File_Size : Stream_Element_Offset := -1;
162 -- Cached value of File_Size, so that we do not keep recomputing it
163 -- when not necessary (otherwise End_Of_File becomes gruesomely slow).
164 -- A value of minus one means that there is no cached value.
166 Last_Op : Operation := Op_Other;
167 -- Last operation performed on file, used to avoid unnecessary
168 -- repositioning between successive read or write operations.
170 Update_Mode : Boolean := False;
171 -- Set if the mode is changed from write to read or vice versa.
172 -- Indicates that the file has been reopened in update mode.
174 end record;
176 type File_Type is access all Stream_AFCB;
178 function AFCB_Allocate (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
180 procedure AFCB_Close (File : access Stream_AFCB);
181 procedure AFCB_Free (File : access Stream_AFCB);
183 procedure Read
184 (File : in out Stream_AFCB;
185 Item : out Ada.Streams.Stream_Element_Array;
186 Last : out Ada.Streams.Stream_Element_Offset);
187 -- Read operation used when Stream_IO file is treated directly as Stream
189 procedure Write
190 (File : in out Stream_AFCB;
191 Item : in Ada.Streams.Stream_Element_Array);
192 -- Write operation used when Stream_IO file is treated directly as Stream
194 end Ada.Streams.Stream_IO;