File: posix-io.ads

package info (click to toggle)
libflorist 2017-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,216 kB
  • sloc: ada: 11,902; ansic: 7,195; makefile: 150; sh: 19
file content (268 lines) | stat: -rw-r--r-- 11,065 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
------------------------------------------------------------------------------
--                                                                          --
--            FLORIST (FSU Implementation of POSIX.5) COMPONENTS            --
--                                                                          --
--                              P O S I X . I O                             --
--                                                                          --
--                                  S p e c                                 --
--                                                                          --
--             Copyright (C) 1996-1997 Florida State University             --
--                     Copyright (C) 1998-2010, AdaCore                     --
--                                                                          --
--  This file is a component of FLORIST, an  implementation of an  Ada API  --
--  for the POSIX OS services, for use with  the  GNAT  Ada  compiler  and  --
--  the FSU Gnu Ada Runtime Library (GNARL).   The  interface  is intended  --
--  to be close to that specified in  IEEE STD  1003.5: 1990  and IEEE STD  --
--  1003.5b: 1996.                                                          --
--                                                                          --
--  FLORIST is free software;  you can  redistribute  it and/or  modify it  --
--  under terms of the  GNU  General  Public  License as  published by the  --
--  Free Software Foundation;  either version  2, or (at  your option) any  --
--  later version.  FLORIST is distributed  in  the hope  that  it will be  --
--  useful, but WITHOUT ANY WARRANTY;  without  even the implied  warranty  --
--  of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE.  See  the GNU  --
--  General Public License for more details.  You  should have  received a  --
--  copy of the GNU General Public License  distributed  with  GNARL;  see  --
--  file  COPYING.  If not,  write to  the  Free  Software  Foundation, 59  --
--  Temple Place - Suite 330, Boston, MA 02111-1307, USA.                   --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
------------------------------------------------------------------------------

with Ada.Streams,
     POSIX,
     POSIX.C,
     POSIX.Permissions,
     POSIX.Process_Identification,
     System;
pragma Elaborate_All (POSIX);
package POSIX.IO is

   type File_Descriptor is
     range 0 .. POSIX.Open_Files_Maxima'Last - 1;
   for File_Descriptor'Size use POSIX.C.int'Size;

   Standard_Input  : constant File_Descriptor := 0;
   Standard_Output : constant File_Descriptor := 1;
   Standard_Error  : constant File_Descriptor := 2;

   type IO_Offset is new POSIX.C.off_t;

   --  File Modes and Options

   type File_Mode is (Read_Only, Write_Only, Read_Write);
   type Open_Option_Set is new POSIX.Option_Set;
   --  Empty_Set, "+" and unary and binary "-" are derived operations

   Non_Blocking             : constant Open_Option_Set;
   Append                   : constant Open_Option_Set;
   Truncate                 : constant Open_Option_Set;
   Exclusive                : constant Open_Option_Set;
   Not_Controlling_Terminal : constant Open_Option_Set;
   File_Synchronized        : constant Open_Option_Set;
   Data_Synchronized        : constant Open_Option_Set;
   Read_Synchronized        : constant Open_Option_Set;

   --  Operations to open or close file descriptors

   function Open
     (Name           : POSIX.Pathname;
      Mode           : File_Mode;
      Options        : Open_Option_Set := Empty_Set;
      Masked_Signals : POSIX.Signal_Masking := POSIX.RTS_Signals)
      return File_Descriptor;

   function Open_Or_Create
     (Name           : POSIX.Pathname;
      Mode           : File_Mode;
      Permissions    : POSIX.Permissions.Permission_Set;
      Options        : Open_Option_Set := Empty_Set;
      Masked_Signals : POSIX.Signal_Masking := POSIX.RTS_Signals)
      return File_Descriptor;

   function Is_Open (File : File_Descriptor) return Boolean;

   procedure Close
     (File           : File_Descriptor;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   function Duplicate
     (File   : File_Descriptor;
      Target : File_Descriptor := 0)
      return File_Descriptor;
   function Duplicate_and_Close
     (File           : File_Descriptor;
      Target         : File_Descriptor := 0;
      Masked_Signals : POSIX.Signal_Masking := POSIX.RTS_Signals)
      return File_Descriptor;
   procedure Create_Pipe
     (Read_End  : out File_Descriptor;
      Write_End : out File_Descriptor);

   --  File Input/Output operations

   subtype IO_Buffer is POSIX.POSIX_String;

   procedure Read
     (File           : File_Descriptor;
      Buffer         : out IO_Buffer;
      Last           : out POSIX.IO_Count;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   procedure NONSTANDARD_Read
     (File           : File_Descriptor;
      Buffer         : out IO_Buffer;
      Last           : out Natural;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   procedure Read
     (File           : File_Descriptor;
      Buffer         : out Ada.Streams.Stream_Element_Array;
      Last           : out Ada.Streams.Stream_Element_Offset;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   procedure Write
     (File           : File_Descriptor;
      Buffer         : IO_Buffer;
      Last           : out POSIX.IO_Count;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   procedure NONSTANDARD_Write
     (File           : File_Descriptor;
      Buffer         : IO_Buffer;
      Last           : out Natural;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   procedure Write
     (File           : File_Descriptor;
      Buffer         : Ada.Streams.Stream_Element_Array;
      Last           : out Ada.Streams.Stream_Element_Offset;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   generic
      type T is private;
   procedure Generic_Read
     (File           : File_Descriptor;
      Item           : out T;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);
   generic
      type T is private;
   procedure Generic_Write
     (File           : File_Descriptor;
      Item           : T;
      Masked_Signals : POSIX.Signal_Masking
                     := POSIX.RTS_Signals);

   --  File position operations

   type Position is
     (From_Beginning, From_Current_Position, From_End_Of_File);
   procedure Seek
     (File           : File_Descriptor;
      Offset         : IO_Offset;
      Result         : out IO_Offset;
      Starting_Point : Position := From_Beginning);
   function File_Size (File : File_Descriptor)
      return POSIX.IO_Count;
   function File_Position (File : File_Descriptor)
      return IO_Offset;

   --  Terminal operations

   function Is_A_Terminal (File : File_Descriptor)
      return Boolean;
   function Get_Terminal_Name (File : File_Descriptor)
      return POSIX.Pathname;

   --  File Control operations

   procedure Get_File_Control
     (File    : File_Descriptor;
      Mode    : out File_Mode;
      Options : out Open_Option_Set);
   procedure Set_File_Control
     (File    : File_Descriptor;
      Options : Open_Option_Set);
   function Get_Close_On_Exec (File : File_Descriptor)
      return Boolean;
   procedure Set_Close_On_Exec
     (File : File_Descriptor;
      To   : Boolean := True);
   procedure Change_Permissions
      (File :        POSIX.IO.File_Descriptor;
       Permission :  POSIX.Permissions.Permission_Set);
   procedure Truncate_File
      (File :        POSIX.IO.File_Descriptor;
       Length :      POSIX.IO_Count);
   procedure Synchronize_File (File : POSIX.IO.File_Descriptor);
   procedure Synchronize_Data (File : POSIX.IO.File_Descriptor);

   --  POSIX.5c/D4 additions

   --  6.1.1 Sockets Option Flags from P1003.5c

   Signal_When_Socket_Ready : constant Open_Option_Set;

   --  6.1.12 Sockets File Ownership procedures from P1003.5c

   procedure Get_Owner
      (File    :  File_Descriptor;
       Process : out POSIX.Process_Identification.Process_ID;
       Group   : out POSIX.Process_Identification.Process_Group_ID);
   procedure Set_Socket_Process_Owner
      (File    : File_Descriptor;
       Process : POSIX.Process_Identification.Process_ID);
   procedure Set_Socket_Group_Owner
      (File    : File_Descriptor;
       Group   : POSIX.Process_Identification.Process_Group_ID);

   type IO_Vector is limited private;
   procedure Set_Buffer
      (Vector : in out IO_Vector;
       Buffer : System.Address;
       Length : Positive);
   procedure Get_Buffer
      (Vector : IO_Vector;
       Buffer : out System.Address;
       Length : out POSIX.IO_Count);

private
   Non_Blocking             : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_NONBLOCK));
   Append                   : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_APPEND));
   --  ....  Change POSIX.5?
   --  This Append hides operation on String_Lists, and vice versa,
   --  if we "use" both this package and POSIX.
   Truncate                 : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_TRUNC));
   Exclusive                : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_EXCL));
   Not_Controlling_Terminal : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_NOCTTY));
   File_Synchronized        : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_SYNC));
   Data_Synchronized        : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_DSYNC));
   Read_Synchronized        : constant Open_Option_Set
     := Open_Option_Set (Option_Set'(Option => POSIX.C.O_RSYNC));

   --  P1003.5c/D4 additions

   Signal_When_Socket_Ready : constant Open_Option_Set :=
     Open_Option_Set (POSIX.Empty_Set);

   type IO_Vector is record
      C : aliased POSIX.C.Sockets.struct_iovec :=
         POSIX.C.Sockets.struct_iovec'(iov_base => null,
                                       iov_len  => 0);
   end record;

end POSIX.IO;