1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT RUN-TIME COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- S Y S T E M . F I L E _ C O N T R O L _ B L O C K --
|
6 |
|
|
-- --
|
7 |
|
|
-- S p e c --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2011, 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 |
|
|
------------------------------------------------------------------------------
|
31 |
|
|
|
32 |
|
|
-- This package contains the declaration of the basic file control block
|
33 |
|
|
-- shared between Text_IO, Sequential_IO, Direct_IO and Streams.Stream_IO.
|
34 |
|
|
-- The actual control blocks are derived from this block by extension. The
|
35 |
|
|
-- control block is itself derived from Ada.Streams.Root_Stream_Type which
|
36 |
|
|
-- facilitates implementation of Stream_IO.Stream and Text_Streams.Stream.
|
37 |
|
|
|
38 |
|
|
with Ada.Streams;
|
39 |
|
|
with Interfaces.C_Streams;
|
40 |
|
|
with System.CRTL;
|
41 |
|
|
|
42 |
|
|
package System.File_Control_Block is
|
43 |
|
|
|
44 |
|
|
----------------------------
|
45 |
|
|
-- Ada File Control Block --
|
46 |
|
|
----------------------------
|
47 |
|
|
|
48 |
|
|
-- The Ada file control block is an abstract extension of the root
|
49 |
|
|
-- stream type. This allows a file to be treated directly as a stream
|
50 |
|
|
-- for the purposes of Stream_IO, or stream operations on a text file.
|
51 |
|
|
-- The individual I/O packages extend this type with package specific
|
52 |
|
|
-- fields to create the concrete types to which the routines in this
|
53 |
|
|
-- package can be applied.
|
54 |
|
|
|
55 |
|
|
-- The type File_Type in the individual packages is an access to the
|
56 |
|
|
-- extended file control block. The value is null if the file is not
|
57 |
|
|
-- open, and a pointer to the control block if the file is open.
|
58 |
|
|
|
59 |
|
|
type Pstring is access all String;
|
60 |
|
|
-- Used to hold name and form strings
|
61 |
|
|
|
62 |
|
|
type File_Mode is (In_File, Inout_File, Out_File, Append_File);
|
63 |
|
|
subtype Read_File_Mode is File_Mode range In_File .. Inout_File;
|
64 |
|
|
-- File mode (union of file modes permitted by individual packages,
|
65 |
|
|
-- the types File_Mode in the individual packages are declared to
|
66 |
|
|
-- allow easy conversion to and from this general type.
|
67 |
|
|
|
68 |
|
|
type Shared_Status_Type is (Yes, No, None);
|
69 |
|
|
-- This type is used to define the sharing status of a file. The default
|
70 |
|
|
-- setting of None is used if no "shared=xxx" appears in the form string
|
71 |
|
|
-- when a file is created or opened. For a file with Shared_Status set to
|
72 |
|
|
-- None, Use_Error will be raised if any other file is opened or created
|
73 |
|
|
-- with the same full name. Yes/No are set in response to the presence
|
74 |
|
|
-- of "shared=yes" or "shared=no" in the form string. In either case it
|
75 |
|
|
-- is permissible to have multiple files opened with the same full name.
|
76 |
|
|
-- All files opened simultaneously with "shared=yes" will share the same
|
77 |
|
|
-- stream with the semantics specified in the RM for file sharing. All
|
78 |
|
|
-- files opened with "shared=no" will have their own stream.
|
79 |
|
|
|
80 |
|
|
type AFCB is tagged;
|
81 |
|
|
type AFCB_Ptr is access all AFCB'Class;
|
82 |
|
|
|
83 |
|
|
type AFCB is abstract new Ada.Streams.Root_Stream_Type with record
|
84 |
|
|
|
85 |
|
|
Stream : Interfaces.C_Streams.FILEs;
|
86 |
|
|
-- The file descriptor
|
87 |
|
|
|
88 |
|
|
Name : Pstring;
|
89 |
|
|
-- A pointer to the file name. The file name is null for temporary
|
90 |
|
|
-- files, and also for standard files (stdin, stdout, stderr). The
|
91 |
|
|
-- name is always null-terminated if it is non-null.
|
92 |
|
|
|
93 |
|
|
Encoding : System.CRTL.Filename_Encoding;
|
94 |
|
|
-- Encoding used to specified the filename
|
95 |
|
|
|
96 |
|
|
Form : Pstring;
|
97 |
|
|
-- A pointer to the form string. This is the string used in the
|
98 |
|
|
-- fopen call, and must be supplied by the caller (there are no
|
99 |
|
|
-- defaults at this level). The string is always null-terminated.
|
100 |
|
|
|
101 |
|
|
Mode : File_Mode;
|
102 |
|
|
-- The file mode. No checks are made that the mode is consistent
|
103 |
|
|
-- with the form used to fopen the file.
|
104 |
|
|
|
105 |
|
|
Is_Regular_File : Boolean;
|
106 |
|
|
-- A flag indicating if the file is a regular file
|
107 |
|
|
|
108 |
|
|
Is_Temporary_File : Boolean;
|
109 |
|
|
-- A flag set only for temporary files (i.e. files created using the
|
110 |
|
|
-- Create function with a null name parameter, using tmpfile). This
|
111 |
|
|
-- is currently not used since temporary files are deleted by the
|
112 |
|
|
-- operating system, but it is set properly in case some systems
|
113 |
|
|
-- need this information in the future.
|
114 |
|
|
|
115 |
|
|
Is_System_File : Boolean;
|
116 |
|
|
-- A flag set only for system files (stdin, stdout, stderr)
|
117 |
|
|
|
118 |
|
|
Is_Text_File : Boolean;
|
119 |
|
|
-- A flag set if the file was opened in text mode
|
120 |
|
|
|
121 |
|
|
Shared_Status : Shared_Status_Type;
|
122 |
|
|
-- Indicates sharing status of file, see description of type above
|
123 |
|
|
|
124 |
|
|
Access_Method : Character;
|
125 |
|
|
-- Set to 'Q', 'S', 'T', 'D' for Sequential_IO, Stream_IO, Text_IO,
|
126 |
|
|
-- Direct_IO file (used to validate file sharing request).
|
127 |
|
|
|
128 |
|
|
Next : AFCB_Ptr;
|
129 |
|
|
Prev : AFCB_Ptr;
|
130 |
|
|
-- All open files are kept on a doubly linked chain, with these
|
131 |
|
|
-- pointers used to maintain the next and previous pointers.
|
132 |
|
|
|
133 |
|
|
end record;
|
134 |
|
|
|
135 |
|
|
----------------------------------
|
136 |
|
|
-- Primitive Operations of AFCB --
|
137 |
|
|
----------------------------------
|
138 |
|
|
|
139 |
|
|
-- Note that we inherit the abstract operations Read and Write from
|
140 |
|
|
-- the base type. These must be overridden by the individual file
|
141 |
|
|
-- access methods to provide Stream Read/Write access.
|
142 |
|
|
|
143 |
|
|
function AFCB_Allocate (Control_Block : AFCB) return AFCB_Ptr is abstract;
|
144 |
|
|
-- Given a control block, allocate space for a control block of the same
|
145 |
|
|
-- type on the heap, and return the pointer to this allocated block. Note
|
146 |
|
|
-- that the argument Control_Block is not used other than as the argument
|
147 |
|
|
-- that controls which version of AFCB_Allocate is called.
|
148 |
|
|
|
149 |
|
|
procedure AFCB_Close (File : not null access AFCB) is abstract;
|
150 |
|
|
-- Performs any specialized close actions on a file before the file is
|
151 |
|
|
-- actually closed at the system level. This is called by Close, and
|
152 |
|
|
-- the reason we need the primitive operation is for the automatic
|
153 |
|
|
-- close operations done as part of finalization.
|
154 |
|
|
|
155 |
|
|
procedure AFCB_Free (File : not null access AFCB) is abstract;
|
156 |
|
|
-- Frees the AFCB referenced by the given parameter. It is not necessary
|
157 |
|
|
-- to free the strings referenced by the Form and Name fields, but if the
|
158 |
|
|
-- extension has any other heap objects, they must be freed as well. This
|
159 |
|
|
-- procedure must be overridden by each individual file package.
|
160 |
|
|
|
161 |
|
|
end System.File_Control_Block;
|