annotate gcc/ada/libgnat/s-fileio.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . F I L E _ I O --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package provides support for the routines described in (RM A.8.2)
kono
parents:
diff changeset
33 -- which are common to Text_IO, Direct_IO, Sequential_IO and Stream_IO.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 with Interfaces.C_Streams;
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 with System.File_Control_Block;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 package System.File_IO is
kono
parents:
diff changeset
40 pragma Preelaborate;
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 package FCB renames System.File_Control_Block;
kono
parents:
diff changeset
43 package ICS renames Interfaces.C_Streams;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 ---------------------
kono
parents:
diff changeset
46 -- File Management --
kono
parents:
diff changeset
47 ---------------------
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 procedure Open
kono
parents:
diff changeset
50 (File_Ptr : in out FCB.AFCB_Ptr;
kono
parents:
diff changeset
51 Dummy_FCB : FCB.AFCB'Class;
kono
parents:
diff changeset
52 Mode : FCB.File_Mode;
kono
parents:
diff changeset
53 Name : String;
kono
parents:
diff changeset
54 Form : String;
kono
parents:
diff changeset
55 Amethod : Character;
kono
parents:
diff changeset
56 Creat : Boolean;
kono
parents:
diff changeset
57 Text : Boolean;
kono
parents:
diff changeset
58 C_Stream : ICS.FILEs := ICS.NULL_Stream);
kono
parents:
diff changeset
59 -- This routine is used for both Open and Create calls:
kono
parents:
diff changeset
60 --
kono
parents:
diff changeset
61 -- File_Ptr is the file type, which must be null on entry
kono
parents:
diff changeset
62 -- (i.e. the file must be closed before the call).
kono
parents:
diff changeset
63 --
kono
parents:
diff changeset
64 -- Dummy_FCB is a default initialized file control block of appropriate
kono
parents:
diff changeset
65 -- type. Note that the tag of this record indicates the type and length
kono
parents:
diff changeset
66 -- of the control block. This control block is used only for the purpose
kono
parents:
diff changeset
67 -- of providing the controlling argument for calling the write version
kono
parents:
diff changeset
68 -- of Allocate_AFCB. It has no other purpose, and its fields are never
kono
parents:
diff changeset
69 -- read or written.
kono
parents:
diff changeset
70 --
kono
parents:
diff changeset
71 -- Mode is the required mode
kono
parents:
diff changeset
72 --
kono
parents:
diff changeset
73 -- Name is the file name, with a null string indicating that a temporary
kono
parents:
diff changeset
74 -- file is to be created (only permitted in create mode, not open mode).
kono
parents:
diff changeset
75 --
kono
parents:
diff changeset
76 -- Creat is True for a create call, and false for an open call
kono
parents:
diff changeset
77 --
kono
parents:
diff changeset
78 -- Text is set True to open the file in text mode (w+t or r+t) instead
kono
parents:
diff changeset
79 -- of the usual binary mode open (w+b or r+b).
kono
parents:
diff changeset
80 --
kono
parents:
diff changeset
81 -- Form is the form string given in the open or create call, this is
kono
parents:
diff changeset
82 -- stored in the AFCB.
kono
parents:
diff changeset
83 --
kono
parents:
diff changeset
84 -- Amethod indicates the access method:
kono
parents:
diff changeset
85 --
kono
parents:
diff changeset
86 -- D = Direct_IO
kono
parents:
diff changeset
87 -- Q = Sequential_IO
kono
parents:
diff changeset
88 -- S = Stream_IO
kono
parents:
diff changeset
89 -- T = Text_IO
kono
parents:
diff changeset
90 -- W = Wide_Text_IO
kono
parents:
diff changeset
91 -- ??? Wide_Wide_Text_IO ???
kono
parents:
diff changeset
92 --
kono
parents:
diff changeset
93 -- C_Stream is left at its default value for the normal case of an
kono
parents:
diff changeset
94 -- Open or Create call as defined in the RM. The only time this is
kono
parents:
diff changeset
95 -- non-null is for the Open call from Ada.xxx_IO.C_Streams.Open.
kono
parents:
diff changeset
96 --
kono
parents:
diff changeset
97 -- On return, if the open/create succeeds, then the fields of File are
kono
parents:
diff changeset
98 -- filled in, and this value is copied to the heap. File_Ptr points to
kono
parents:
diff changeset
99 -- this allocated file control block. If the open/create fails, then the
kono
parents:
diff changeset
100 -- fields of File are undefined, and File_Ptr is unchanged.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 procedure Close (File_Ptr : access FCB.AFCB_Ptr);
kono
parents:
diff changeset
103 -- The file is closed, all storage associated with it is released, and
kono
parents:
diff changeset
104 -- File is set to null. Note that this routine calls AFCB_Close to perform
kono
parents:
diff changeset
105 -- any specialized close actions, then closes the file at the system level,
kono
parents:
diff changeset
106 -- then frees the mode and form strings, and finally calls AFCB_Free to
kono
parents:
diff changeset
107 -- free the file control block itself, setting File.all to null. Note that
kono
parents:
diff changeset
108 -- for this assignment to be done in all cases, including those where
kono
parents:
diff changeset
109 -- an exception is raised, we can't use an IN OUT parameter (which would
kono
parents:
diff changeset
110 -- not be copied back in case of abnormal return).
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 procedure Delete (File_Ptr : access FCB.AFCB_Ptr);
kono
parents:
diff changeset
113 -- The indicated file is unlinked
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 procedure Reset (File_Ptr : access FCB.AFCB_Ptr; Mode : FCB.File_Mode);
kono
parents:
diff changeset
116 -- The file is reset, and the mode changed as indicated
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 procedure Reset (File_Ptr : access FCB.AFCB_Ptr);
kono
parents:
diff changeset
119 -- The files is reset, and the mode is unchanged
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 function Mode (File : FCB.AFCB_Ptr) return FCB.File_Mode;
kono
parents:
diff changeset
122 -- Returns the mode as supplied by create, open or reset
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 function Name (File : FCB.AFCB_Ptr) return String;
kono
parents:
diff changeset
125 -- Returns the file name as supplied by Open or Create. Raises Use_Error
kono
parents:
diff changeset
126 -- if used with temporary files or standard files.
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 function Form (File : FCB.AFCB_Ptr) return String;
kono
parents:
diff changeset
129 -- Returns the form as supplied by create, open or reset The string is
kono
parents:
diff changeset
130 -- normalized to all lower case letters.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 function Is_Open (File : FCB.AFCB_Ptr) return Boolean;
kono
parents:
diff changeset
133 -- Determines if file is open or not
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 ----------------------
kono
parents:
diff changeset
136 -- Utility Routines --
kono
parents:
diff changeset
137 ----------------------
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 -- Some internal routines not defined in A.8.2. These are routines which
kono
parents:
diff changeset
140 -- provide required common functionality shared by separate packages.
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 procedure Chain_File (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
143 -- Used to chain the given file into the list of open files. Normally this
kono
parents:
diff changeset
144 -- is done implicitly by Open. Chain_File is used for the special cases of
kono
parents:
diff changeset
145 -- the system files defined by Text_IO (stdin, stdout, stderr) which are
kono
parents:
diff changeset
146 -- not opened in the normal manner. Note that the caller is responsible
kono
parents:
diff changeset
147 -- for task lock out to protect the global data structures if this is
kono
parents:
diff changeset
148 -- necessary (it is needed for the calls from within this unit itself,
kono
parents:
diff changeset
149 -- but not required for the calls from Text_IO and [Wide_]Wide_Text_IO
kono
parents:
diff changeset
150 -- that are made during elaboration of the environment task).
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 procedure Check_File_Open (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
153 -- If the current file is not open, then Status_Error is raised. Otherwise
kono
parents:
diff changeset
154 -- control returns normally (with File pointing to the control block for
kono
parents:
diff changeset
155 -- the open file.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 procedure Check_Read_Status (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
158 -- If the current file is not open, then Status_Error is raised. If the
kono
parents:
diff changeset
159 -- file is open, then the mode is checked to make sure that reading is
kono
parents:
diff changeset
160 -- permitted, and if not Mode_Error is raised, otherwise control returns
kono
parents:
diff changeset
161 -- normally.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 procedure Check_Write_Status (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
164 -- If the current file is not open, then Status_Error is raised. If the
kono
parents:
diff changeset
165 -- file is open, then the mode is checked to ensure that writing is
kono
parents:
diff changeset
166 -- permitted, and if not Mode_Error is raised, otherwise control returns
kono
parents:
diff changeset
167 -- normally.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 function End_Of_File (File : FCB.AFCB_Ptr) return Boolean;
kono
parents:
diff changeset
170 -- File must be opened in read mode. True is returned if the stream is
kono
parents:
diff changeset
171 -- currently positioned at the end of file, otherwise False is returned.
kono
parents:
diff changeset
172 -- The position of the stream is not affected.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 procedure Flush (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
175 -- Flushes the stream associated with the given file. The file must be open
kono
parents:
diff changeset
176 -- and in write mode (if not, an appropriate exception is raised)
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 function Form_Boolean
kono
parents:
diff changeset
179 (Form : String;
kono
parents:
diff changeset
180 Keyword : String;
kono
parents:
diff changeset
181 Default : Boolean) return Boolean;
kono
parents:
diff changeset
182 -- Searches form string for an entry of the form keyword=xx where xx is
kono
parents:
diff changeset
183 -- either yes/no or y/n. Returns True if yes or y is found, False if no or
kono
parents:
diff changeset
184 -- n is found. If the keyword parameter is not found, returns the value
kono
parents:
diff changeset
185 -- given as Default. May raise Use_Error if a form string syntax error is
kono
parents:
diff changeset
186 -- detected. Keyword and Form must be in lower case.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 function Form_Integer
kono
parents:
diff changeset
189 (Form : String;
kono
parents:
diff changeset
190 Keyword : String;
kono
parents:
diff changeset
191 Default : Integer) return Integer;
kono
parents:
diff changeset
192 -- Searches form string for an entry of the form Keyword=xx where xx is an
kono
parents:
diff changeset
193 -- unsigned decimal integer in the range 0 to 999_999. Returns this integer
kono
parents:
diff changeset
194 -- value if it is found. If the keyword parameter is not found, returns the
kono
parents:
diff changeset
195 -- value given as Default. Raise Use_Error if a form string syntax error is
kono
parents:
diff changeset
196 -- detected. Keyword and Form must be in lower case.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 procedure Form_Parameter
kono
parents:
diff changeset
199 (Form : String;
kono
parents:
diff changeset
200 Keyword : String;
kono
parents:
diff changeset
201 Start : out Natural;
kono
parents:
diff changeset
202 Stop : out Natural);
kono
parents:
diff changeset
203 -- Searches form string for an entry of the form Keyword=xx and if found
kono
parents:
diff changeset
204 -- Sets Start and Stop to the first and last characters of xx. Keyword
kono
parents:
diff changeset
205 -- and Form must be in lower case. If no entry matches, then Start and
kono
parents:
diff changeset
206 -- Stop are set to zero on return. Use_Error is raised if a malformed
kono
parents:
diff changeset
207 -- string is detected, but there is no guarantee of full syntax checking.
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 procedure Read_Buf
kono
parents:
diff changeset
210 (File : FCB.AFCB_Ptr;
kono
parents:
diff changeset
211 Buf : Address;
kono
parents:
diff changeset
212 Siz : Interfaces.C_Streams.size_t);
kono
parents:
diff changeset
213 -- Reads Siz bytes from File.Stream into Buf. The caller has checked
kono
parents:
diff changeset
214 -- that the file is open in read mode. Raises an exception if Siz bytes
kono
parents:
diff changeset
215 -- cannot be read (End_Error if no data was read, Data_Error if a partial
kono
parents:
diff changeset
216 -- buffer was read, Device_Error if an error occurs).
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 procedure Read_Buf
kono
parents:
diff changeset
219 (File : FCB.AFCB_Ptr;
kono
parents:
diff changeset
220 Buf : Address;
kono
parents:
diff changeset
221 Siz : Interfaces.C_Streams.size_t;
kono
parents:
diff changeset
222 Count : out Interfaces.C_Streams.size_t);
kono
parents:
diff changeset
223 -- Reads Siz bytes from File.Stream into Buf. The caller has checked that
kono
parents:
diff changeset
224 -- the file is open in read mode. Device Error is raised if an error
kono
parents:
diff changeset
225 -- occurs. Count is the actual number of bytes read, which may be less
kono
parents:
diff changeset
226 -- than Siz if the end of file is encountered.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 procedure Append_Set (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
229 -- If the mode of the file is Append_File, then the file is positioned at
kono
parents:
diff changeset
230 -- the end of file using fseek, otherwise this call has no effect.
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 procedure Write_Buf
kono
parents:
diff changeset
233 (File : FCB.AFCB_Ptr;
kono
parents:
diff changeset
234 Buf : Address;
kono
parents:
diff changeset
235 Siz : Interfaces.C_Streams.size_t);
kono
parents:
diff changeset
236 -- Writes size_t bytes to File.Stream from Buf. The caller has checked that
kono
parents:
diff changeset
237 -- the file is open in write mode. Raises Device_Error if the complete
kono
parents:
diff changeset
238 -- buffer cannot be written.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 procedure Make_Unbuffered (File : FCB.AFCB_Ptr);
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 procedure Make_Line_Buffered
kono
parents:
diff changeset
243 (File : FCB.AFCB_Ptr;
kono
parents:
diff changeset
244 Line_Siz : Interfaces.C_Streams.size_t);
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 procedure Make_Buffered
kono
parents:
diff changeset
247 (File : FCB.AFCB_Ptr;
kono
parents:
diff changeset
248 Buf_Siz : Interfaces.C_Streams.size_t);
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 private
kono
parents:
diff changeset
251 pragma Inline (Check_Read_Status);
kono
parents:
diff changeset
252 pragma Inline (Check_Write_Status);
kono
parents:
diff changeset
253 pragma Inline (Mode);
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 end System.File_IO;