annotate gcc/ada/libgnat/i-vxwoio.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 LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- I N T E R F A C E S . V X W O R K S . 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) 2002-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL 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 -- GNARL was developed by the GNARL team at Florida State 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 a binding to the functions fileno and ioctl
kono
parents:
diff changeset
33 -- in VxWorks, providing a set of definitions of ioctl function codes
kono
parents:
diff changeset
34 -- and options for the use of these functions.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- A particular use of this interface is to enable use of Get_Immediate
kono
parents:
diff changeset
37 -- in Ada.Text_IO. There is no way in VxWorks to provide the desired
kono
parents:
diff changeset
38 -- functionality of Get_Immediate (no buffering and no waiting for a
kono
parents:
diff changeset
39 -- line return) without flushing the buffer, which violates the Ada
kono
parents:
diff changeset
40 -- semantic requirements for Ada.Text_IO.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with Interfaces.C_Streams;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 package Interfaces.VxWorks.IO is
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 -------------------------
kono
parents:
diff changeset
47 -- The ioctl Interface --
kono
parents:
diff changeset
48 --------------------------
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 type FUNCODE is new int;
kono
parents:
diff changeset
51 -- Type of the function codes in ioctl
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 type IOOPT is mod 2 ** int'Size;
kono
parents:
diff changeset
54 -- Type of the option codes in ioctl
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 -- ioctl function codes (for more information see ioLib.h)
kono
parents:
diff changeset
57 -- These values could be generated automatically in System.OS_Constants???
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 FIONREAD : constant FUNCODE := 1;
kono
parents:
diff changeset
60 FIOFLUSH : constant FUNCODE := 2;
kono
parents:
diff changeset
61 FIOOPTIONS : constant FUNCODE := 3;
kono
parents:
diff changeset
62 FIOBAUDRATE : constant FUNCODE := 4;
kono
parents:
diff changeset
63 FIODISKFORMAT : constant FUNCODE := 5;
kono
parents:
diff changeset
64 FIODISKINIT : constant FUNCODE := 6;
kono
parents:
diff changeset
65 FIOSEEK : constant FUNCODE := 7;
kono
parents:
diff changeset
66 FIOWHERE : constant FUNCODE := 8;
kono
parents:
diff changeset
67 FIODIRENTRY : constant FUNCODE := 9;
kono
parents:
diff changeset
68 FIORENAME : constant FUNCODE := 10;
kono
parents:
diff changeset
69 FIOREADYCHANGE : constant FUNCODE := 11;
kono
parents:
diff changeset
70 FIONWRITE : constant FUNCODE := 12;
kono
parents:
diff changeset
71 FIODISKCHANGE : constant FUNCODE := 13;
kono
parents:
diff changeset
72 FIOCANCEL : constant FUNCODE := 14;
kono
parents:
diff changeset
73 FIOSQUEEZE : constant FUNCODE := 15;
kono
parents:
diff changeset
74 FIONBIO : constant FUNCODE := 16;
kono
parents:
diff changeset
75 FIONMSGS : constant FUNCODE := 17;
kono
parents:
diff changeset
76 FIOGETNAME : constant FUNCODE := 18;
kono
parents:
diff changeset
77 FIOGETOPTIONS : constant FUNCODE := 19;
kono
parents:
diff changeset
78 FIOSETOPTIONS : constant FUNCODE := FIOOPTIONS;
kono
parents:
diff changeset
79 FIOISATTY : constant FUNCODE := 20;
kono
parents:
diff changeset
80 FIOSYNC : constant FUNCODE := 21;
kono
parents:
diff changeset
81 FIOPROTOHOOK : constant FUNCODE := 22;
kono
parents:
diff changeset
82 FIOPROTOARG : constant FUNCODE := 23;
kono
parents:
diff changeset
83 FIORBUFSET : constant FUNCODE := 24;
kono
parents:
diff changeset
84 FIOWBUFSET : constant FUNCODE := 25;
kono
parents:
diff changeset
85 FIORFLUSH : constant FUNCODE := 26;
kono
parents:
diff changeset
86 FIOWFLUSH : constant FUNCODE := 27;
kono
parents:
diff changeset
87 FIOSELECT : constant FUNCODE := 28;
kono
parents:
diff changeset
88 FIOUNSELECT : constant FUNCODE := 29;
kono
parents:
diff changeset
89 FIONFREE : constant FUNCODE := 30;
kono
parents:
diff changeset
90 FIOMKDIR : constant FUNCODE := 31;
kono
parents:
diff changeset
91 FIORMDIR : constant FUNCODE := 32;
kono
parents:
diff changeset
92 FIOLABELGET : constant FUNCODE := 33;
kono
parents:
diff changeset
93 FIOLABELSET : constant FUNCODE := 34;
kono
parents:
diff changeset
94 FIOATTRIBSE : constant FUNCODE := 35;
kono
parents:
diff changeset
95 FIOCONTIG : constant FUNCODE := 36;
kono
parents:
diff changeset
96 FIOREADDIR : constant FUNCODE := 37;
kono
parents:
diff changeset
97 FIOFSTATGET : constant FUNCODE := 38;
kono
parents:
diff changeset
98 FIOUNMOUNT : constant FUNCODE := 39;
kono
parents:
diff changeset
99 FIOSCSICOMMAND : constant FUNCODE := 40;
kono
parents:
diff changeset
100 FIONCONTIG : constant FUNCODE := 41;
kono
parents:
diff changeset
101 FIOTRUNC : constant FUNCODE := 42;
kono
parents:
diff changeset
102 FIOGETFL : constant FUNCODE := 43;
kono
parents:
diff changeset
103 FIOTIMESET : constant FUNCODE := 44;
kono
parents:
diff changeset
104 FIOINODETONAM : constant FUNCODE := 45;
kono
parents:
diff changeset
105 FIOFSTATFSGE : constant FUNCODE := 46;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 -- ioctl option values
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 OPT_ECHO : constant IOOPT := 16#0001#;
kono
parents:
diff changeset
110 OPT_CRMOD : constant IOOPT := 16#0002#;
kono
parents:
diff changeset
111 OPT_TANDEM : constant IOOPT := 16#0004#;
kono
parents:
diff changeset
112 OPT_7_BIT : constant IOOPT := 16#0008#;
kono
parents:
diff changeset
113 OPT_MON_TRAP : constant IOOPT := 16#0010#;
kono
parents:
diff changeset
114 OPT_ABORT : constant IOOPT := 16#0020#;
kono
parents:
diff changeset
115 OPT_LINE : constant IOOPT := 16#0040#;
kono
parents:
diff changeset
116 OPT_RAW : constant IOOPT := 16#0000#;
kono
parents:
diff changeset
117 OPT_TERMINAL : constant IOOPT := OPT_ECHO or
kono
parents:
diff changeset
118 OPT_CRMOD or
kono
parents:
diff changeset
119 OPT_TANDEM or
kono
parents:
diff changeset
120 OPT_MON_TRAP or
kono
parents:
diff changeset
121 OPT_7_BIT or
kono
parents:
diff changeset
122 OPT_ABORT or
kono
parents:
diff changeset
123 OPT_LINE;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 function fileno (Fp : Interfaces.C_Streams.FILEs) return int;
kono
parents:
diff changeset
126 pragma Import (C, fileno, "fileno");
kono
parents:
diff changeset
127 -- Binding to the C routine fileno
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 function ioctl (Fd : int; Function_Code : FUNCODE; Arg : IOOPT) return int;
kono
parents:
diff changeset
130 pragma Import (C, ioctl, "ioctl");
kono
parents:
diff changeset
131 -- Binding to the C routine ioctl
kono
parents:
diff changeset
132 --
kono
parents:
diff changeset
133 -- Note: we are taking advantage of the fact that on currently supported
kono
parents:
diff changeset
134 -- VxWorks targets, it is fine to directly bind to a variadic C function.
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 ------------------------------
kono
parents:
diff changeset
137 -- Control of Get_Immediate --
kono
parents:
diff changeset
138 ------------------------------
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 -- The procedures in this section make use of the interface to ioctl
kono
parents:
diff changeset
141 -- and fileno to provide a mechanism for enabling unbuffered behavior
kono
parents:
diff changeset
142 -- for Get_Immediate in VxWorks.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 -- The situation is that the RM requires that the use of Get_Immediate
kono
parents:
diff changeset
145 -- be identical to Get except that it is desirable (not required) that
kono
parents:
diff changeset
146 -- there be no buffering or line editing.
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 -- Unfortunately, in VxWorks, the only way to enable this desired
kono
parents:
diff changeset
149 -- unbuffered behavior involves changing into raw mode. But this
kono
parents:
diff changeset
150 -- transition into raw mode flushes the input buffer, a behavior
kono
parents:
diff changeset
151 -- not permitted by the RM semantics for Get_Immediate.
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 -- Given that Get_Immediate cannot be accurately implemented in
kono
parents:
diff changeset
154 -- raw mode, it seems best not to enable it by default, and instead
kono
parents:
diff changeset
155 -- to require specific programmer action, with the programmer being
kono
parents:
diff changeset
156 -- aware that input may be lost.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 -- The following is an example of the use of the two procedures
kono
parents:
diff changeset
159 -- in this section (Enable_Get_Immediate and Disable_Get_Immediate)
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 -- with Ada.Text_IO; use Ada.Text_IO;
kono
parents:
diff changeset
162 -- with Ada.Text_IO.C_Streams; use Ada.Text_IO.C_Streams;
kono
parents:
diff changeset
163 -- with Interfaces.VxWorks.IO; use Interfaces.VxWorks.IO;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 -- procedure Example_IO is
kono
parents:
diff changeset
166 -- Input : Character;
kono
parents:
diff changeset
167 -- Available : Boolean;
kono
parents:
diff changeset
168 -- Success : Boolean;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 -- begin
kono
parents:
diff changeset
171 -- Enable_Get_Immediate (C_Stream (Current_Input), Success);
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 -- if Success = False then
kono
parents:
diff changeset
174 -- raise Device_Error;
kono
parents:
diff changeset
175 -- end if;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 -- -- Example with the first type of Get_Immediate
kono
parents:
diff changeset
178 -- -- Waits for an entry on the input. Immediately returns
kono
parents:
diff changeset
179 -- -- after having received an character on the input
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 -- Put ("Input -> ");
kono
parents:
diff changeset
182 -- Get_Immediate (Input);
kono
parents:
diff changeset
183 -- New_Line;
kono
parents:
diff changeset
184 -- Put_Line ("Character read: " & Input);
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 -- -- Example with the second type of Get_Immediate
kono
parents:
diff changeset
187 -- -- This is equivalent to a non blocking read
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 -- for J in 1 .. 10 loop
kono
parents:
diff changeset
190 -- Put ("Input -> ");
kono
parents:
diff changeset
191 -- Get_Immediate (Input, Available);
kono
parents:
diff changeset
192 -- New_Line;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 -- if Available = True then
kono
parents:
diff changeset
195 -- Put_Line ("Character read: " & Input);
kono
parents:
diff changeset
196 -- end if;
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 -- delay 1.0;
kono
parents:
diff changeset
199 -- end loop;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 -- Disable_Get_Immediate (C_Stream (Current_Input), Success);
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 -- if Success = False then
kono
parents:
diff changeset
204 -- raise Device_Error;
kono
parents:
diff changeset
205 -- end if;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 -- exception
kono
parents:
diff changeset
208 -- when Device_Error =>
kono
parents:
diff changeset
209 -- Put_Line ("Device Error. Check your configuration");
kono
parents:
diff changeset
210 -- end Example_IO;
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 procedure Enable_Get_Immediate
kono
parents:
diff changeset
213 (File : Interfaces.C_Streams.FILEs;
kono
parents:
diff changeset
214 Success : out Boolean);
kono
parents:
diff changeset
215 -- On VxWorks, a call to this procedure is required before subsequent calls
kono
parents:
diff changeset
216 -- to Get_Immediate have the desired effect of not waiting for a line
kono
parents:
diff changeset
217 -- return. The reason that this call is not automatic on this target is
kono
parents:
diff changeset
218 -- that the call flushes the input buffer, discarding any previous input.
kono
parents:
diff changeset
219 -- Note: Following a call to Enable_Get_Immediate, the only permitted
kono
parents:
diff changeset
220 -- operations on the relevant file are Get_Immediate operations. Any
kono
parents:
diff changeset
221 -- other operations have undefined behavior.
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 procedure Disable_Get_Immediate
kono
parents:
diff changeset
224 (File : Interfaces.C_Streams.FILEs;
kono
parents:
diff changeset
225 Success : out Boolean);
kono
parents:
diff changeset
226 -- This procedure resets File to standard mode, and permits subsequent
kono
parents:
diff changeset
227 -- use of the full range of Ada.Text_IO functions
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 end Interfaces.VxWorks.IO;