annotate gcc/ada/sysdep.c @ 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 COMPILER COMPONENTS *
kono
parents:
diff changeset
4 * *
kono
parents:
diff changeset
5 * S Y S D E P *
kono
parents:
diff changeset
6 * *
kono
parents:
diff changeset
7 * C Implementation File *
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 file contains system dependent symbols that are referenced in the
kono
parents:
diff changeset
33 GNAT Run Time Library */
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 #ifdef __vxworks
kono
parents:
diff changeset
36 #include "ioLib.h"
kono
parents:
diff changeset
37 #if ! defined (VTHREADS)
kono
parents:
diff changeset
38 #include "dosFsLib.h"
kono
parents:
diff changeset
39 #endif
kono
parents:
diff changeset
40 #if ! defined (__RTP__) && (! defined (VTHREADS) || defined (__VXWORKSMILS__))
kono
parents:
diff changeset
41 # include "nfsLib.h"
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43 #include "selectLib.h"
kono
parents:
diff changeset
44 #include "vxWorks.h"
kono
parents:
diff changeset
45 #include "version.h"
kono
parents:
diff changeset
46 #if defined (__RTP__)
kono
parents:
diff changeset
47 # include "vwModNum.h"
kono
parents:
diff changeset
48 #endif /* __RTP__ */
kono
parents:
diff changeset
49 #endif
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 #ifdef __ANDROID__
kono
parents:
diff changeset
52 #undef __linux__
kono
parents:
diff changeset
53 #endif
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 #ifdef IN_RTS
kono
parents:
diff changeset
56 #define POSIX
kono
parents:
diff changeset
57 #include "tconfig.h"
kono
parents:
diff changeset
58 #include "tsystem.h"
kono
parents:
diff changeset
59 #include <fcntl.h>
kono
parents:
diff changeset
60 #include <sys/stat.h>
kono
parents:
diff changeset
61 #else
kono
parents:
diff changeset
62 #include "config.h"
kono
parents:
diff changeset
63 #include "system.h"
kono
parents:
diff changeset
64 #endif
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 #include <time.h>
kono
parents:
diff changeset
67 #include <errno.h>
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 #if defined (__sun__) && !defined (__vxworks)
kono
parents:
diff changeset
70 /* The declaration is present in <time.h> but conditionalized
kono
parents:
diff changeset
71 on a couple of macros we don't define. */
kono
parents:
diff changeset
72 extern struct tm *localtime_r(const time_t *, struct tm *);
kono
parents:
diff changeset
73 #endif
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 #include "adaint.h"
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* Don't use macros versions of this functions on VxWorks since they cause
kono
parents:
diff changeset
78 imcompatible changes in some VxWorks versions */
kono
parents:
diff changeset
79 #ifdef __vxworks
kono
parents:
diff changeset
80 #undef getchar
kono
parents:
diff changeset
81 #undef putchar
kono
parents:
diff changeset
82 #undef feof
kono
parents:
diff changeset
83 #undef ferror
kono
parents:
diff changeset
84 #undef fileno
kono
parents:
diff changeset
85 #endif
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /*
kono
parents:
diff changeset
88 Notes:
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 (1) Opening a file with read mode fails if the file does not exist or
kono
parents:
diff changeset
91 cannot be read.
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 (2) Opening a file with append mode causes all subsequent writes to the
kono
parents:
diff changeset
94 file to be forced to the then current end-of-file, regardless of
kono
parents:
diff changeset
95 intervening calls to the fseek function.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 (3) When a file is opened with update mode, both input and output may be
kono
parents:
diff changeset
98 performed on the associated stream. However, output may not be directly
kono
parents:
diff changeset
99 followed by input without an intervening call to the fflush function or
kono
parents:
diff changeset
100 to a file positioning function (fseek, fsetpos, or rewind), and input
kono
parents:
diff changeset
101 may not be directly followed by output without an intervening call to a
kono
parents:
diff changeset
102 file positioning function, unless the input operation encounters
kono
parents:
diff changeset
103 end-of-file.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 The other target dependent declarations here are for the three functions
kono
parents:
diff changeset
106 __gnat_set_binary_mode, __gnat_set_text_mode and __gnat_set_mode:
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 void __gnat_set_binary_mode (int handle);
kono
parents:
diff changeset
109 void __gnat_set_text_mode (int handle);
kono
parents:
diff changeset
110 void __gnat_set_mode (int handle, int mode);
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 These functions have no effect in Unix (or similar systems where there is
kono
parents:
diff changeset
113 no distinction between binary and text files), but in DOS (and similar
kono
parents:
diff changeset
114 systems where text mode does CR/LF translation), these functions allow
kono
parents:
diff changeset
115 the mode of the stream with the given handle (fileno can be used to get
kono
parents:
diff changeset
116 the handle of a stream) to be changed dynamically. The returned result
kono
parents:
diff changeset
117 is 0 if no error occurs and -1 if an error occurs.
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 Finally there is a boolean (character) variable
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 char __gnat_text_translation_required;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 which is zero (false) in Unix mode, and one (true) in DOS mode, with a
kono
parents:
diff changeset
124 true value indicating that text translation is required on text files
kono
parents:
diff changeset
125 and that fopen supports the trailing t and b modifiers.
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 */
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 #if defined (WINNT) || defined (__CYGWIN__) || defined (__DJGPP__)
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 const char __gnat_text_translation_required = 1;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 #ifdef __CYGWIN__
kono
parents:
diff changeset
134 #define WIN_SETMODE setmode
kono
parents:
diff changeset
135 #include <io.h>
kono
parents:
diff changeset
136 #else
kono
parents:
diff changeset
137 #define WIN_SETMODE _setmode
kono
parents:
diff changeset
138 #endif
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 #if defined (__DJGPP__)
kono
parents:
diff changeset
141 #include <io.h>
kono
parents:
diff changeset
142 #define _setmode setmode
kono
parents:
diff changeset
143 #endif /* __DJGPP__ */
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 void
kono
parents:
diff changeset
146 __gnat_set_binary_mode (int handle)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 WIN_SETMODE (handle, O_BINARY);
kono
parents:
diff changeset
149 }
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 void
kono
parents:
diff changeset
152 __gnat_set_text_mode (int handle)
kono
parents:
diff changeset
153 {
kono
parents:
diff changeset
154 WIN_SETMODE (handle, O_TEXT);
kono
parents:
diff changeset
155 }
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 #if defined (__CYGWIN__) || defined (__DJGPP__)
kono
parents:
diff changeset
158 void
kono
parents:
diff changeset
159 __gnat_set_mode (int handle, int mode)
kono
parents:
diff changeset
160 {
kono
parents:
diff changeset
161 /* the values here must be synchronized with
kono
parents:
diff changeset
162 System.File_Control_Block.Content_Encodding:
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 None = 0
kono
parents:
diff changeset
165 Default_Text = 1
kono
parents:
diff changeset
166 Text = 2
kono
parents:
diff changeset
167 U8text = 3
kono
parents:
diff changeset
168 Wtext = 4
kono
parents:
diff changeset
169 U16text = 5 */
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 switch (mode) {
kono
parents:
diff changeset
172 case 0 : setmode(handle, O_BINARY); break;
kono
parents:
diff changeset
173 case 1 : setmode(handle, O_TEXT); break;
kono
parents:
diff changeset
174 case 2 : setmode(handle, O_TEXT); break;
kono
parents:
diff changeset
175 case 3 : setmode(handle, O_TEXT); break;
kono
parents:
diff changeset
176 case 4 : setmode(handle, O_BINARY); break;
kono
parents:
diff changeset
177 case 5 : setmode(handle, O_BINARY); break;
kono
parents:
diff changeset
178 }
kono
parents:
diff changeset
179 }
kono
parents:
diff changeset
180 #else
kono
parents:
diff changeset
181 void
kono
parents:
diff changeset
182 __gnat_set_mode (int handle, int mode)
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 /* the values here must be synchronized with
kono
parents:
diff changeset
185 System.File_Control_Block.Content_Encodding:
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 None = 0
kono
parents:
diff changeset
188 Default_Text = 1
kono
parents:
diff changeset
189 Text = 2
kono
parents:
diff changeset
190 U8text = 3
kono
parents:
diff changeset
191 Wtext = 4
kono
parents:
diff changeset
192 U16text = 5 */
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 switch (mode) {
kono
parents:
diff changeset
195 case 0 : WIN_SETMODE (handle, _O_BINARY); break;
kono
parents:
diff changeset
196 case 1 : WIN_SETMODE (handle, __gnat_current_ccs_encoding); break;
kono
parents:
diff changeset
197 case 2 : WIN_SETMODE (handle, _O_TEXT); break;
kono
parents:
diff changeset
198 case 3 : WIN_SETMODE (handle, _O_U8TEXT); break;
kono
parents:
diff changeset
199 case 4 : WIN_SETMODE (handle, _O_WTEXT); break;
kono
parents:
diff changeset
200 case 5 : WIN_SETMODE (handle, _O_U16TEXT); break;
kono
parents:
diff changeset
201 }
kono
parents:
diff changeset
202 }
kono
parents:
diff changeset
203 #endif
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 #ifdef __CYGWIN__
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 char *
kono
parents:
diff changeset
208 __gnat_ttyname (int filedes)
kono
parents:
diff changeset
209 {
kono
parents:
diff changeset
210 extern char *ttyname (int);
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 return ttyname (filedes);
kono
parents:
diff changeset
213 }
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 #endif /* __CYGWIN__ */
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 #if defined (__CYGWIN__) || defined (__MINGW32__)
kono
parents:
diff changeset
218 #include <windows.h>
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 int __gnat_is_windows_xp (void);
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 int
kono
parents:
diff changeset
223 __gnat_is_windows_xp (void)
kono
parents:
diff changeset
224 {
kono
parents:
diff changeset
225 static int is_win_xp=0, is_win_xp_checked=0;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 if (!is_win_xp_checked)
kono
parents:
diff changeset
228 {
kono
parents:
diff changeset
229 OSVERSIONINFO version;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 is_win_xp_checked = 1;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 memset (&version, 0, sizeof (version));
kono
parents:
diff changeset
234 version.dwOSVersionInfoSize = sizeof (version);
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 is_win_xp = GetVersionEx (&version)
kono
parents:
diff changeset
237 && version.dwPlatformId == VER_PLATFORM_WIN32_NT
kono
parents:
diff changeset
238 && (version.dwMajorVersion > 5
kono
parents:
diff changeset
239 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1));
kono
parents:
diff changeset
240 }
kono
parents:
diff changeset
241 return is_win_xp;
kono
parents:
diff changeset
242 }
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 /* Get the bounds of the stack. The stack pointer is supposed to be
kono
parents:
diff changeset
245 initialized to BASE when a thread is created and the stack can be extended
kono
parents:
diff changeset
246 to LIMIT before reaching a guard page.
kono
parents:
diff changeset
247 Note: for the main thread, the system automatically extend the stack, so
kono
parents:
diff changeset
248 LIMIT is only the current limit. */
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 void
kono
parents:
diff changeset
251 __gnat_get_stack_bounds (void **base, void **limit)
kono
parents:
diff changeset
252 {
kono
parents:
diff changeset
253 NT_TIB *tib;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 /* We know that the first field of the TEB is the TIB. */
kono
parents:
diff changeset
256 tib = (NT_TIB *)NtCurrentTeb ();
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 *base = tib->StackBase;
kono
parents:
diff changeset
259 *limit = tib->StackLimit;
kono
parents:
diff changeset
260 }
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 #endif /* __CYGWIN__ || __MINGW32__ */
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 #ifdef __MINGW32__
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 /* Return the name of the tty. Under windows there is no name for
kono
parents:
diff changeset
267 the tty, so this function, if connected to a tty, returns the generic name
kono
parents:
diff changeset
268 "console". */
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 char *
kono
parents:
diff changeset
271 __gnat_ttyname (int filedes)
kono
parents:
diff changeset
272 {
kono
parents:
diff changeset
273 if (isatty (filedes))
kono
parents:
diff changeset
274 return "console";
kono
parents:
diff changeset
275 else
kono
parents:
diff changeset
276 return NULL;
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 #endif /* __MINGW32__ */
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 #else
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 const char __gnat_text_translation_required = 0;
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 /* These functions do nothing in non-DOS systems. */
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 void
kono
parents:
diff changeset
288 __gnat_set_binary_mode (int handle ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 }
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 void
kono
parents:
diff changeset
293 __gnat_set_text_mode (int handle ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
294 {
kono
parents:
diff changeset
295 }
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 void
kono
parents:
diff changeset
298 __gnat_set_mode (int handle ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
299 {
kono
parents:
diff changeset
300 }
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 char *
kono
parents:
diff changeset
303 __gnat_ttyname (int filedes)
kono
parents:
diff changeset
304 {
kono
parents:
diff changeset
305 #if defined (__vxworks)
kono
parents:
diff changeset
306 return "";
kono
parents:
diff changeset
307 #else
kono
parents:
diff changeset
308 extern char *ttyname (int);
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 return ttyname (filedes);
kono
parents:
diff changeset
311 #endif /* defined (__vxworks) */
kono
parents:
diff changeset
312 }
kono
parents:
diff changeset
313 #endif
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 #if defined (__linux__) || defined (__sun__) \
kono
parents:
diff changeset
316 || defined (WINNT) \
kono
parents:
diff changeset
317 || defined (__MACHTEN__) || defined (__hpux__) || defined (_AIX) \
kono
parents:
diff changeset
318 || (defined (__svr4__) && defined (__i386__)) || defined (__Lynx__) \
kono
parents:
diff changeset
319 || defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321 || defined (__QNX__)
111
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 # ifdef __MINGW32__
kono
parents:
diff changeset
324 # if OLD_MINGW
kono
parents:
diff changeset
325 # include <termios.h>
kono
parents:
diff changeset
326 # else
kono
parents:
diff changeset
327 # include <conio.h> /* for getch(), kbhit() */
kono
parents:
diff changeset
328 # endif
kono
parents:
diff changeset
329 # else
kono
parents:
diff changeset
330 # include <termios.h>
kono
parents:
diff changeset
331 # endif
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 #endif
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 /* Implements the common processing for getc_immediate and
kono
parents:
diff changeset
336 getc_immediate_nowait. */
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 extern void getc_immediate (FILE *, int *, int *);
kono
parents:
diff changeset
339 extern void getc_immediate_nowait (FILE *, int *, int *, int *);
kono
parents:
diff changeset
340 extern void getc_immediate_common (FILE *, int *, int *, int *, int);
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 /* Called by Get_Immediate (Foo); */
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 void
kono
parents:
diff changeset
345 getc_immediate (FILE *stream, int *ch, int *end_of_file)
kono
parents:
diff changeset
346 {
kono
parents:
diff changeset
347 int avail;
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 getc_immediate_common (stream, ch, end_of_file, &avail, 1);
kono
parents:
diff changeset
350 }
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 /* Called by Get_Immediate (Foo, Available); */
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 void
kono
parents:
diff changeset
355 getc_immediate_nowait (FILE *stream, int *ch, int *end_of_file, int *avail)
kono
parents:
diff changeset
356 {
kono
parents:
diff changeset
357 getc_immediate_common (stream, ch, end_of_file, avail, 0);
kono
parents:
diff changeset
358 }
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 /* Called by getc_immediate () and getc_immediate_nowait () */
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 void
kono
parents:
diff changeset
363 getc_immediate_common (FILE *stream,
kono
parents:
diff changeset
364 int *ch,
kono
parents:
diff changeset
365 int *end_of_file,
kono
parents:
diff changeset
366 int *avail,
kono
parents:
diff changeset
367 int waiting ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
368 {
kono
parents:
diff changeset
369 #if defined (__linux__) || defined (__sun__) \
kono
parents:
diff changeset
370 || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
kono
parents:
diff changeset
371 || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
kono
parents:
diff changeset
372 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
373 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
374 || defined (__QNX__)
111
kono
parents:
diff changeset
375 char c;
kono
parents:
diff changeset
376 int nread;
kono
parents:
diff changeset
377 int good_one = 0;
kono
parents:
diff changeset
378 int eof_ch = 4; /* Ctrl-D */
kono
parents:
diff changeset
379 int fd = fileno (stream);
kono
parents:
diff changeset
380 struct termios otermios_rec, termios_rec;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 if (isatty (fd))
kono
parents:
diff changeset
383 {
kono
parents:
diff changeset
384 tcgetattr (fd, &termios_rec);
kono
parents:
diff changeset
385 memcpy (&otermios_rec, &termios_rec, sizeof (struct termios));
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 /* Set RAW mode, with no echo */
kono
parents:
diff changeset
388 termios_rec.c_lflag = termios_rec.c_lflag & ~ICANON & ~ECHO;
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 #if defined (__linux__) || defined (__sun__) \
kono
parents:
diff changeset
391 || defined (__MACHTEN__) || defined (__hpux__) \
kono
parents:
diff changeset
392 || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
kono
parents:
diff changeset
393 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
394 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
395 || defined (__QNX__)
111
kono
parents:
diff changeset
396 eof_ch = termios_rec.c_cc[VEOF];
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 /* If waiting (i.e. Get_Immediate (Char)), set MIN = 1 and wait for
kono
parents:
diff changeset
399 a character forever. This doesn't seem to effect Ctrl-Z or
kono
parents:
diff changeset
400 Ctrl-C processing.
kono
parents:
diff changeset
401 If not waiting (i.e. Get_Immediate (Char, Available)),
kono
parents:
diff changeset
402 don't wait for anything but timeout immediately. */
kono
parents:
diff changeset
403 termios_rec.c_cc[VMIN] = waiting;
kono
parents:
diff changeset
404 termios_rec.c_cc[VTIME] = 0;
kono
parents:
diff changeset
405 #endif
kono
parents:
diff changeset
406 tcsetattr (fd, TCSANOW, &termios_rec);
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 while (! good_one)
kono
parents:
diff changeset
409 {
kono
parents:
diff changeset
410 /* Read is used here instead of fread, because fread doesn't
kono
parents:
diff changeset
411 work on Solaris5 and Sunos4 in this situation. Maybe because we
kono
parents:
diff changeset
412 are mixing calls that use file descriptors and streams. */
kono
parents:
diff changeset
413 nread = read (fd, &c, 1);
kono
parents:
diff changeset
414 if (nread > 0)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 /* On Unix terminals, Ctrl-D (EOT) is an End of File. */
kono
parents:
diff changeset
417 if (c == eof_ch)
kono
parents:
diff changeset
418 {
kono
parents:
diff changeset
419 *avail = 0;
kono
parents:
diff changeset
420 *end_of_file = 1;
kono
parents:
diff changeset
421 good_one = 1;
kono
parents:
diff changeset
422 }
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 /* Everything else is ok */
kono
parents:
diff changeset
425 else if (c != eof_ch)
kono
parents:
diff changeset
426 {
kono
parents:
diff changeset
427 *avail = 1;
kono
parents:
diff changeset
428 *end_of_file = 0;
kono
parents:
diff changeset
429 good_one = 1;
kono
parents:
diff changeset
430 }
kono
parents:
diff changeset
431 }
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 else if (! waiting)
kono
parents:
diff changeset
434 {
kono
parents:
diff changeset
435 *avail = 0;
kono
parents:
diff changeset
436 *end_of_file = 0;
kono
parents:
diff changeset
437 good_one = 1;
kono
parents:
diff changeset
438 }
kono
parents:
diff changeset
439 else
kono
parents:
diff changeset
440 good_one = 0;
kono
parents:
diff changeset
441 }
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 tcsetattr (fd, TCSANOW, &otermios_rec);
kono
parents:
diff changeset
444 *ch = c;
kono
parents:
diff changeset
445 }
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 else
kono
parents:
diff changeset
448 #elif defined (__MINGW32__)
kono
parents:
diff changeset
449 int fd = fileno (stream);
kono
parents:
diff changeset
450 int char_waiting;
kono
parents:
diff changeset
451 int eot_ch = 4; /* Ctrl-D */
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 if (isatty (fd))
kono
parents:
diff changeset
454 {
kono
parents:
diff changeset
455 if (waiting)
kono
parents:
diff changeset
456 {
kono
parents:
diff changeset
457 *ch = getch ();
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 if (*ch == eot_ch)
kono
parents:
diff changeset
460 *end_of_file = 1;
kono
parents:
diff changeset
461 else
kono
parents:
diff changeset
462 *end_of_file = 0;
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 *avail = 1;
kono
parents:
diff changeset
465 }
kono
parents:
diff changeset
466 else /* ! waiting */
kono
parents:
diff changeset
467 {
kono
parents:
diff changeset
468 char_waiting = kbhit();
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 if (char_waiting == 1)
kono
parents:
diff changeset
471 {
kono
parents:
diff changeset
472 *avail = 1;
kono
parents:
diff changeset
473 *ch = getch ();
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 if (*ch == eot_ch)
kono
parents:
diff changeset
476 *end_of_file = 1;
kono
parents:
diff changeset
477 else
kono
parents:
diff changeset
478 *end_of_file = 0;
kono
parents:
diff changeset
479 }
kono
parents:
diff changeset
480 else
kono
parents:
diff changeset
481 {
kono
parents:
diff changeset
482 *avail = 0;
kono
parents:
diff changeset
483 *end_of_file = 0;
kono
parents:
diff changeset
484 }
kono
parents:
diff changeset
485 }
kono
parents:
diff changeset
486 }
kono
parents:
diff changeset
487 else
kono
parents:
diff changeset
488 #elif defined (__vxworks)
kono
parents:
diff changeset
489 /* Bit masks of file descriptors to read from. */
kono
parents:
diff changeset
490 struct fd_set readFds;
kono
parents:
diff changeset
491 /* Timeout before select returns if nothing can be read. */
kono
parents:
diff changeset
492 struct timeval timeOut;
kono
parents:
diff changeset
493 char c;
kono
parents:
diff changeset
494 int fd = fileno (stream);
kono
parents:
diff changeset
495 int nread;
kono
parents:
diff changeset
496 int option;
kono
parents:
diff changeset
497 int readable;
kono
parents:
diff changeset
498 int status;
kono
parents:
diff changeset
499 int width;
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 if (isatty (fd))
kono
parents:
diff changeset
502 {
kono
parents:
diff changeset
503 /* If we do not want to wait, we have to set up fd in RAW mode. This
kono
parents:
diff changeset
504 should be done outside this function as setting fd in RAW mode under
kono
parents:
diff changeset
505 vxWorks flushes the buffer of fd. If the RAW mode was set here, the
kono
parents:
diff changeset
506 buffer would be empty and we would always return that no character
kono
parents:
diff changeset
507 is available */
kono
parents:
diff changeset
508 if (! waiting)
kono
parents:
diff changeset
509 {
kono
parents:
diff changeset
510 /* Initialization of timeOut for its use with select. */
kono
parents:
diff changeset
511 timeOut.tv_sec = 0;
kono
parents:
diff changeset
512 timeOut.tv_usec = 0;
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 /* Initialization of readFds for its use with select;
kono
parents:
diff changeset
515 FD is the only file descriptor to be monitored */
kono
parents:
diff changeset
516 FD_ZERO (&readFds);
kono
parents:
diff changeset
517 FD_SET (fd, &readFds);
kono
parents:
diff changeset
518 width = 2;
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 /* We do all this processing to emulate a non blocking read. */
kono
parents:
diff changeset
521 readable = select (width, &readFds, NULL, NULL, &timeOut);
kono
parents:
diff changeset
522 if (readable == ERROR)
kono
parents:
diff changeset
523 *avail = -1, *end_of_file = -1;
kono
parents:
diff changeset
524 /* No character available in input. */
kono
parents:
diff changeset
525 else if (readable == 0)
kono
parents:
diff changeset
526 *avail = 0, *end_of_file = 0;
kono
parents:
diff changeset
527 else
kono
parents:
diff changeset
528 {
kono
parents:
diff changeset
529 nread = read (fd, &c, 1);
kono
parents:
diff changeset
530 if (nread > 0)
kono
parents:
diff changeset
531 *avail = 1, *end_of_file = 0;
kono
parents:
diff changeset
532 /* End Of File. */
kono
parents:
diff changeset
533 else if (nread == 0)
kono
parents:
diff changeset
534 *avail = 0, *end_of_file = 1;
kono
parents:
diff changeset
535 /* Error. */
kono
parents:
diff changeset
536 else
kono
parents:
diff changeset
537 *avail = -1, *end_of_file = -1;
kono
parents:
diff changeset
538 }
kono
parents:
diff changeset
539 }
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 /* We have to wait until we get a character */
kono
parents:
diff changeset
542 else
kono
parents:
diff changeset
543 {
kono
parents:
diff changeset
544 *avail = -1;
kono
parents:
diff changeset
545 *end_of_file = -1;
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 /* Save the current mode of FD. */
kono
parents:
diff changeset
548 option = ioctl (fd, FIOGETOPTIONS, 0);
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 /* Set FD in RAW mode. */
kono
parents:
diff changeset
551 status = ioctl (fd, FIOSETOPTIONS, OPT_RAW);
kono
parents:
diff changeset
552 if (status != -1)
kono
parents:
diff changeset
553 {
kono
parents:
diff changeset
554 nread = read (fd, &c, 1);
kono
parents:
diff changeset
555 if (nread > 0)
kono
parents:
diff changeset
556 *avail = 1, *end_of_file = 0;
kono
parents:
diff changeset
557 /* End of file. */
kono
parents:
diff changeset
558 else if (nread == 0)
kono
parents:
diff changeset
559 *avail = 0, *end_of_file = 1;
kono
parents:
diff changeset
560 /* Else there is an ERROR. */
kono
parents:
diff changeset
561 }
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 /* Revert FD to its previous mode. */
kono
parents:
diff changeset
564 status = ioctl (fd, FIOSETOPTIONS, option);
kono
parents:
diff changeset
565 }
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 *ch = c;
kono
parents:
diff changeset
568 }
kono
parents:
diff changeset
569 else
kono
parents:
diff changeset
570 #endif
kono
parents:
diff changeset
571 {
kono
parents:
diff changeset
572 /* If we're not on a terminal, then we don't need any fancy processing.
kono
parents:
diff changeset
573 Also this is the only thing that's left if we're not on one of the
kono
parents:
diff changeset
574 supported systems; which means that for non supported systems,
kono
parents:
diff changeset
575 get_immediate may wait for a carriage return on terminals. */
kono
parents:
diff changeset
576 *ch = fgetc (stream);
kono
parents:
diff changeset
577 if (feof (stream))
kono
parents:
diff changeset
578 {
kono
parents:
diff changeset
579 *end_of_file = 1;
kono
parents:
diff changeset
580 *avail = 0;
kono
parents:
diff changeset
581 }
kono
parents:
diff changeset
582 else
kono
parents:
diff changeset
583 {
kono
parents:
diff changeset
584 *end_of_file = 0;
kono
parents:
diff changeset
585 *avail = 1;
kono
parents:
diff changeset
586 }
kono
parents:
diff changeset
587 }
kono
parents:
diff changeset
588 }
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 /* The following definitions are provided in NT to support Windows based
kono
parents:
diff changeset
591 Ada programs. */
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 #ifdef WINNT
kono
parents:
diff changeset
594 #include <windows.h>
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 /* Provide functions to echo the values passed to WinMain (windows bindings
kono
parents:
diff changeset
597 will want to import these). We use the same names as the routines used
kono
parents:
diff changeset
598 by AdaMagic for compatibility. */
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 char *rts_get_hInstance (void);
kono
parents:
diff changeset
601 char *rts_get_hPrevInstance (void);
kono
parents:
diff changeset
602 char *rts_get_lpCommandLine (void);
kono
parents:
diff changeset
603 int rts_get_nShowCmd (void);
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 char *
kono
parents:
diff changeset
606 rts_get_hInstance (void)
kono
parents:
diff changeset
607 {
kono
parents:
diff changeset
608 return (char *)GetModuleHandleA (0);
kono
parents:
diff changeset
609 }
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 char *
kono
parents:
diff changeset
612 rts_get_hPrevInstance (void)
kono
parents:
diff changeset
613 {
kono
parents:
diff changeset
614 return 0;
kono
parents:
diff changeset
615 }
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 char *
kono
parents:
diff changeset
618 rts_get_lpCommandLine (void)
kono
parents:
diff changeset
619 {
kono
parents:
diff changeset
620 return GetCommandLineA ();
kono
parents:
diff changeset
621 }
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 int
kono
parents:
diff changeset
624 rts_get_nShowCmd (void)
kono
parents:
diff changeset
625 {
kono
parents:
diff changeset
626 return 1;
kono
parents:
diff changeset
627 }
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 #endif /* WINNT */
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 /* This value is returned as the time zone offset when a valid value
kono
parents:
diff changeset
632 cannot be determined. It is simply a bizarre value that will never
kono
parents:
diff changeset
633 occur. It is 3 days plus 73 seconds (offset is in seconds). */
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 long __gnat_invalid_tzoff = 259273;
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 /* Definition of __gnat_localtime_r used by a-calend.adb */
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 #if defined (__MINGW32__)
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 /* Reentrant localtime for Windows. */
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 extern void
kono
parents:
diff changeset
644 __gnat_localtime_tzoff (const time_t *, const int *, long *);
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 static const unsigned long long w32_epoch_offset = 11644473600ULL;
kono
parents:
diff changeset
647 void
kono
parents:
diff changeset
648 __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
kono
parents:
diff changeset
649 {
kono
parents:
diff changeset
650 TIME_ZONE_INFORMATION tzi;
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 DWORD tzi_status;
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 tzi_status = GetTimeZoneInformation (&tzi);
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 /* Cases where we simply want to extract the offset of the current time
kono
parents:
diff changeset
657 zone, regardless of the date. A value of "0" for flag "is_historic"
kono
parents:
diff changeset
658 signifies that the date is NOT historic, see the
kono
parents:
diff changeset
659 body of Ada.Calendar.UTC_Time_Offset. */
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 if (*is_historic == 0) {
kono
parents:
diff changeset
662 *off = tzi.Bias;
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 /* The system is operating in the range covered by the StandardDate
kono
parents:
diff changeset
665 member. */
kono
parents:
diff changeset
666 if (tzi_status == TIME_ZONE_ID_STANDARD) {
kono
parents:
diff changeset
667 *off = *off + tzi.StandardBias;
kono
parents:
diff changeset
668 }
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 /* The system is operating in the range covered by the DaylightDate
kono
parents:
diff changeset
671 member. */
kono
parents:
diff changeset
672 else if (tzi_status == TIME_ZONE_ID_DAYLIGHT) {
kono
parents:
diff changeset
673 *off = *off + tzi.DaylightBias;
kono
parents:
diff changeset
674 }
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 *off = *off * -60;
kono
parents:
diff changeset
677 }
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 /* Time zone offset calculations for a historic or future date */
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 else {
kono
parents:
diff changeset
682 union
kono
parents:
diff changeset
683 {
kono
parents:
diff changeset
684 FILETIME ft_time;
kono
parents:
diff changeset
685 unsigned long long ull_time;
kono
parents:
diff changeset
686 } utc_time, local_time;
kono
parents:
diff changeset
687
kono
parents:
diff changeset
688 SYSTEMTIME utc_sys_time, local_sys_time;
kono
parents:
diff changeset
689 BOOL status;
kono
parents:
diff changeset
690
kono
parents:
diff changeset
691 /* First convert unix time_t structure to windows FILETIME format. */
kono
parents:
diff changeset
692 utc_time.ull_time = ((unsigned long long) *timer + w32_epoch_offset)
kono
parents:
diff changeset
693 * 10000000ULL;
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 /* If GetTimeZoneInformation does not return a value between 0 and 2 then
kono
parents:
diff changeset
696 it means that we were not able to retrieve timezone information. Note
kono
parents:
diff changeset
697 that we cannot use here FileTimeToLocalFileTime as Windows will use in
kono
parents:
diff changeset
698 always in this case the current timezone setting. As suggested on MSDN
kono
parents:
diff changeset
699 we use the following three system calls to get the right information.
kono
parents:
diff changeset
700 Note also that starting with Windows Vista new functions are provided
kono
parents:
diff changeset
701 to get timezone settings that depend on the year. We cannot use them as
kono
parents:
diff changeset
702 we still support Windows XP and Windows 2003. */
kono
parents:
diff changeset
703
kono
parents:
diff changeset
704 status = (tzi_status >= 0 && tzi_status <= 2)
kono
parents:
diff changeset
705 && FileTimeToSystemTime (&utc_time.ft_time, &utc_sys_time)
kono
parents:
diff changeset
706 && SystemTimeToTzSpecificLocalTime (&tzi, &utc_sys_time, &local_sys_time)
kono
parents:
diff changeset
707 && SystemTimeToFileTime (&local_sys_time, &local_time.ft_time);
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 /* An error has occurred, return invalid_tzoff */
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 if (!status) {
kono
parents:
diff changeset
712 *off = __gnat_invalid_tzoff;
kono
parents:
diff changeset
713 }
kono
parents:
diff changeset
714 else {
kono
parents:
diff changeset
715 if (local_time.ull_time > utc_time.ull_time) {
kono
parents:
diff changeset
716 *off = (long) ((local_time.ull_time - utc_time.ull_time)
kono
parents:
diff changeset
717 / 10000000ULL);
kono
parents:
diff changeset
718 }
kono
parents:
diff changeset
719 else {
kono
parents:
diff changeset
720 *off = - (long) ((utc_time.ull_time - local_time.ull_time)
kono
parents:
diff changeset
721 / 10000000ULL);
kono
parents:
diff changeset
722 }
kono
parents:
diff changeset
723 }
kono
parents:
diff changeset
724 }
kono
parents:
diff changeset
725 }
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 #elif defined (__Lynx__)
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 /* On Lynx, all time values are treated in GMT */
kono
parents:
diff changeset
730
kono
parents:
diff changeset
731 /* As of LynxOS 3.1.0a patch level 040, LynuxWorks changes the
kono
parents:
diff changeset
732 prototype to the C library function localtime_r from the POSIX.4
kono
parents:
diff changeset
733 Draft 9 to the POSIX 1.c version. Before this change the following
kono
parents:
diff changeset
734 spec is required. Only use when ___THREADS_POSIX4ad4__ is defined,
kono
parents:
diff changeset
735 the Lynx convention when building against the legacy API. */
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 extern void
kono
parents:
diff changeset
738 __gnat_localtime_tzoff (const time_t *, const int *, long *);
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 void
kono
parents:
diff changeset
741 __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
kono
parents:
diff changeset
742 {
kono
parents:
diff changeset
743 *off = 0;
kono
parents:
diff changeset
744 }
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 #else
kono
parents:
diff changeset
747
kono
parents:
diff changeset
748 /* Other targets except Lynx and Windows provide a standard localtime_r */
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 #define Lock_Task system__soft_links__lock_task
kono
parents:
diff changeset
751 extern void (*Lock_Task) (void);
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 #define Unlock_Task system__soft_links__unlock_task
kono
parents:
diff changeset
754 extern void (*Unlock_Task) (void);
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 extern void
kono
parents:
diff changeset
757 __gnat_localtime_tzoff (const time_t *, const int *, long *);
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 void
kono
parents:
diff changeset
760 __gnat_localtime_tzoff (const time_t *timer ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
761 const int *is_historic ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
762 long *off ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
763 {
kono
parents:
diff changeset
764 struct tm tp ATTRIBUTE_UNUSED;
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 /* AIX, HPUX, Sun Solaris */
kono
parents:
diff changeset
767 #if defined (_AIX) || defined (__hpux__) || defined (__sun__)
kono
parents:
diff changeset
768 {
kono
parents:
diff changeset
769 (*Lock_Task) ();
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 localtime_r (timer, &tp);
kono
parents:
diff changeset
772 *off = (long) -timezone;
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 (*Unlock_Task) ();
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 /* Correct the offset if Daylight Saving Time is in effect */
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 if (tp.tm_isdst > 0)
kono
parents:
diff changeset
779 *off = *off + 3600;
kono
parents:
diff changeset
780 }
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 /* VxWorks */
kono
parents:
diff changeset
783 #elif defined (__vxworks)
kono
parents:
diff changeset
784 #include <stdlib.h>
kono
parents:
diff changeset
785 {
kono
parents:
diff changeset
786 (*Lock_Task) ();
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 localtime_r (timer, &tp);
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 /* Try to read the environment variable TIMEZONE. The variable may not have
kono
parents:
diff changeset
791 been initialize, in that case return an offset of zero (0) for UTC. */
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 char *tz_str = getenv ("TIMEZONE");
kono
parents:
diff changeset
794
kono
parents:
diff changeset
795 if ((tz_str == NULL) || (*tz_str == '\0'))
kono
parents:
diff changeset
796 *off = 0;
kono
parents:
diff changeset
797 else
kono
parents:
diff changeset
798 {
kono
parents:
diff changeset
799 char *tz_start, *tz_end;
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 /* The format of the data contained in TIMEZONE is N::U:S:E where N is the
kono
parents:
diff changeset
802 name of the time zone, U are the minutes difference from UTC, S is the
kono
parents:
diff changeset
803 start of DST in mmddhh and E is the end of DST in mmddhh. Extracting
kono
parents:
diff changeset
804 the value of U involves setting two pointers, one at the beginning and
kono
parents:
diff changeset
805 one at the end of the value. The end pointer is then set to null in
kono
parents:
diff changeset
806 order to delimit a string slice for atol to process. */
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 tz_start = index (tz_str, ':') + 2;
kono
parents:
diff changeset
809 tz_end = index (tz_start, ':');
kono
parents:
diff changeset
810 *tz_end = '\0';
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 /* The Ada layer expects an offset in seconds. Note that we must reverse
kono
parents:
diff changeset
813 the sign of the result since west is positive and east is negative on
kono
parents:
diff changeset
814 VxWorks targets. */
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 *off = -atol (tz_start) * 60;
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 /* Correct the offset if Daylight Saving Time is in effect */
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 if (tp.tm_isdst > 0)
kono
parents:
diff changeset
821 *off = *off + 3600;
kono
parents:
diff changeset
822 }
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 (*Unlock_Task) ();
kono
parents:
diff changeset
825 }
kono
parents:
diff changeset
826
kono
parents:
diff changeset
827 /* Darwin, Free BSD, Linux, where component tm_gmtoff is present in
kono
parents:
diff changeset
828 struct tm */
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 #elif defined (__APPLE__) || defined (__FreeBSD__) || defined (__linux__) \
kono
parents:
diff changeset
831 || defined (__GLIBC__) || defined (__DragonFly__) || defined (__OpenBSD__) \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
832 || defined (__DJGPP__) || defined (__QNX__)
111
kono
parents:
diff changeset
833 {
kono
parents:
diff changeset
834 localtime_r (timer, &tp);
kono
parents:
diff changeset
835 *off = tp.tm_gmtoff;
kono
parents:
diff changeset
836 }
kono
parents:
diff changeset
837
kono
parents:
diff changeset
838 /* Default: treat all time values in GMT */
kono
parents:
diff changeset
839
kono
parents:
diff changeset
840 #else
kono
parents:
diff changeset
841 *off = 0;
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 #endif /* defined(_AIX) ... */
kono
parents:
diff changeset
844 }
kono
parents:
diff changeset
845
kono
parents:
diff changeset
846 #endif
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 #ifdef __vxworks
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 #include <taskLib.h>
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 /* __gnat_get_task_options is used by s-taprop.adb only for VxWorks. This
kono
parents:
diff changeset
853 function returns the options to be set when creating a new task. It fetches
kono
parents:
diff changeset
854 the options assigned to the current task (parent), so offering some user
kono
parents:
diff changeset
855 level control over the options for a task hierarchy. It forces VX_FP_TASK
kono
parents:
diff changeset
856 because it is almost always required. On processors with the SPE
kono
parents:
diff changeset
857 category, VX_SPE_TASK should be used instead to enable the SPE. */
kono
parents:
diff changeset
858 extern int __gnat_get_task_options (void);
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 int
kono
parents:
diff changeset
861 __gnat_get_task_options (void)
kono
parents:
diff changeset
862 {
kono
parents:
diff changeset
863 int options;
kono
parents:
diff changeset
864
kono
parents:
diff changeset
865 /* Get the options for the task creator */
kono
parents:
diff changeset
866 taskOptionsGet (taskIdSelf (), &options);
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 /* Force VX_FP_TASK or VX_SPE_TASK as needed */
kono
parents:
diff changeset
869 #if defined (__SPE__)
kono
parents:
diff changeset
870 options |= VX_SPE_TASK;
kono
parents:
diff changeset
871 #else
kono
parents:
diff changeset
872 options |= VX_FP_TASK;
kono
parents:
diff changeset
873 #endif
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 /* Mask those bits that are not under user control */
kono
parents:
diff changeset
876 #ifdef VX_USR_TASK_OPTIONS
kono
parents:
diff changeset
877 /* O810-007, TSR 00043679:
kono
parents:
diff changeset
878 Workaround a bug in Vx-7 where VX_DEALLOC_TCB == VX_PRIVATE_UMASK and:
kono
parents:
diff changeset
879 - VX_DEALLOC_TCB is an internal option not to be used by users
kono
parents:
diff changeset
880 - VX_PRIVATE_UMASK as a user-definable option
kono
parents:
diff changeset
881 This leads to VX_USR_TASK_OPTIONS allowing 0x8000 as VX_PRIVATE_UMASK but
kono
parents:
diff changeset
882 taskCreate refusing this option (VX_DEALLOC_TCB is not allowed)
kono
parents:
diff changeset
883
kono
parents:
diff changeset
884 Note that the same error occurs in both RTP and Kernel mode, but
kono
parents:
diff changeset
885 VX_DEALLOC_TCB is not defined in the RTP headers, so we need to
kono
parents:
diff changeset
886 explicitely check if VX_PRIVATE_UMASK has value 0x8000
kono
parents:
diff changeset
887 */
kono
parents:
diff changeset
888 # if defined (VX_PRIVATE_UMASK) && (0x8000 == VX_PRIVATE_UMASK)
kono
parents:
diff changeset
889 options &= ~VX_PRIVATE_UMASK;
kono
parents:
diff changeset
890 # endif
kono
parents:
diff changeset
891 options &= VX_USR_TASK_OPTIONS;
kono
parents:
diff changeset
892 #endif
kono
parents:
diff changeset
893 return options;
kono
parents:
diff changeset
894 }
kono
parents:
diff changeset
895
kono
parents:
diff changeset
896 #endif
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 int
kono
parents:
diff changeset
899 __gnat_is_file_not_found_error (int errno_val) {
kono
parents:
diff changeset
900 switch (errno_val) {
kono
parents:
diff changeset
901 case ENOENT:
kono
parents:
diff changeset
902 #ifdef __vxworks
kono
parents:
diff changeset
903 /* In the case of VxWorks, we also have to take into account various
kono
parents:
diff changeset
904 * filesystem-specific variants of this error.
kono
parents:
diff changeset
905 */
kono
parents:
diff changeset
906 #if ! defined (VTHREADS) && (_WRS_VXWORKS_MAJOR < 7)
kono
parents:
diff changeset
907 case S_dosFsLib_FILE_NOT_FOUND:
kono
parents:
diff changeset
908 #endif
kono
parents:
diff changeset
909 #if ! defined (__RTP__) && (! defined (VTHREADS) || defined (__VXWORKSMILS__))
kono
parents:
diff changeset
910 case S_nfsLib_NFSERR_NOENT:
kono
parents:
diff changeset
911 #endif
kono
parents:
diff changeset
912 #if defined (__RTP__)
kono
parents:
diff changeset
913 /* An RTP can return an NFS file not found, and the NFS bits must
kono
parents:
diff changeset
914 first be masked on to check the errno. */
kono
parents:
diff changeset
915 case M_nfsStat | ENOENT:
kono
parents:
diff changeset
916 #endif
kono
parents:
diff changeset
917 #endif
kono
parents:
diff changeset
918 return 1;
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 default:
kono
parents:
diff changeset
921 return 0;
kono
parents:
diff changeset
922 }
kono
parents:
diff changeset
923 }
kono
parents:
diff changeset
924
kono
parents:
diff changeset
925 #if defined (__linux__)
kono
parents:
diff changeset
926
kono
parents:
diff changeset
927 /* Note well: If this code is modified, it should be tested by hand,
kono
parents:
diff changeset
928 because automated testing doesn't exercise it.
kono
parents:
diff changeset
929 */
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 /* HAVE_CAPABILITY is supposed to be defined if sys/capability.h exists on the
kono
parents:
diff changeset
932 system where this is being compiled. If this macro is defined, we #include
kono
parents:
diff changeset
933 the header. Otherwise we have the relevant declarations textually here.
kono
parents:
diff changeset
934 */
kono
parents:
diff changeset
935
kono
parents:
diff changeset
936 #if defined (HAVE_CAPABILITY)
kono
parents:
diff changeset
937 #include <sys/capability.h>
kono
parents:
diff changeset
938 #else
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 /* HAVE_CAPABILITY is not defined, so sys/capability.h does might not exist. */
kono
parents:
diff changeset
941
kono
parents:
diff changeset
942 typedef struct _cap_struct *cap_t;
kono
parents:
diff changeset
943 typedef enum {
kono
parents:
diff changeset
944 CAP_CLEAR=0,
kono
parents:
diff changeset
945 CAP_SET=1
kono
parents:
diff changeset
946 } cap_flag_value_t;
kono
parents:
diff changeset
947 #define CAP_SYS_NICE 23
kono
parents:
diff changeset
948 typedef enum {
kono
parents:
diff changeset
949 CAP_EFFECTIVE=0, /* Specifies the effective flag */
kono
parents:
diff changeset
950 CAP_PERMITTED=1, /* Specifies the permitted flag */
kono
parents:
diff changeset
951 CAP_INHERITABLE=2 /* Specifies the inheritable flag */
kono
parents:
diff changeset
952 } cap_flag_t;
kono
parents:
diff changeset
953
kono
parents:
diff changeset
954 typedef int cap_value_t;
kono
parents:
diff changeset
955
kono
parents:
diff changeset
956 extern cap_t cap_get_proc(void);
kono
parents:
diff changeset
957 extern int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
kono
parents:
diff changeset
958 extern int cap_free(void *);
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 #endif
kono
parents:
diff changeset
961
kono
parents:
diff changeset
962 /* __gnat_has_cap_sys_nice returns 1 if the current process has the
kono
parents:
diff changeset
963 CAP_SYS_NICE capability. This capability is necessary to use the
kono
parents:
diff changeset
964 Ceiling_Locking policy. Returns 0 otherwise. Note that this is
kono
parents:
diff changeset
965 defined only for Linux.
kono
parents:
diff changeset
966 */
kono
parents:
diff changeset
967
kono
parents:
diff changeset
968 /* Define these as weak symbols, so if support for capabilities is not present,
kono
parents:
diff changeset
969 programs can still link. On Ubuntu, support for capabilities can be
kono
parents:
diff changeset
970 installed via "sudo apt-get --assume-yes install libcap-dev".
kono
parents:
diff changeset
971 In addition, the user must link with "-lcap", or else these
kono
parents:
diff changeset
972 symbols will be 0, and __gnat_has_cap_sys_nice will return 0.
kono
parents:
diff changeset
973 */
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 static cap_t cap_get_proc_weak(void)
kono
parents:
diff changeset
976 __attribute__ ((weakref ("cap_get_proc")));
kono
parents:
diff changeset
977 static int cap_get_flag_weak(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *)
kono
parents:
diff changeset
978 __attribute__ ((weakref ("cap_get_flag")));
kono
parents:
diff changeset
979 static int cap_free_weak(void *)
kono
parents:
diff changeset
980 __attribute__ ((weakref ("cap_free")));
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 int
kono
parents:
diff changeset
983 __gnat_has_cap_sys_nice () {
kono
parents:
diff changeset
984 /* If the address of cap_get_proc_weak is 0, this means support for
kono
parents:
diff changeset
985 capabilities is not present, so we return 0. */
kono
parents:
diff changeset
986 if (&cap_get_proc_weak == 0)
kono
parents:
diff changeset
987 return 0;
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 cap_t caps = cap_get_proc_weak();
kono
parents:
diff changeset
990 if (caps == NULL)
kono
parents:
diff changeset
991 return 0;
kono
parents:
diff changeset
992
kono
parents:
diff changeset
993 cap_flag_value_t value;
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 if (cap_get_flag_weak(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &value) == -1)
kono
parents:
diff changeset
996 return 0;
kono
parents:
diff changeset
997
kono
parents:
diff changeset
998 if (cap_free_weak(caps) == -1)
kono
parents:
diff changeset
999 return 0;
kono
parents:
diff changeset
1000
kono
parents:
diff changeset
1001 if (value == CAP_SET)
kono
parents:
diff changeset
1002 return 1;
kono
parents:
diff changeset
1003
kono
parents:
diff changeset
1004 return 0;
kono
parents:
diff changeset
1005 }
kono
parents:
diff changeset
1006 #endif
kono
parents:
diff changeset
1007
kono
parents:
diff changeset
1008 #ifdef __ANDROID__
kono
parents:
diff changeset
1009
kono
parents:
diff changeset
1010 /* Provide extern symbols for sig* as needed by the tasking run-time, instead
kono
parents:
diff changeset
1011 of static inline functions. */
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 #include <signal.h>
kono
parents:
diff changeset
1014
kono
parents:
diff changeset
1015 int
kono
parents:
diff changeset
1016 _sigismember (sigset_t *set, int signum)
kono
parents:
diff changeset
1017 {
kono
parents:
diff changeset
1018 return sigismember (set, signum);
kono
parents:
diff changeset
1019 }
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 int
kono
parents:
diff changeset
1022 _sigaddset (sigset_t *set, int signum)
kono
parents:
diff changeset
1023 {
kono
parents:
diff changeset
1024 return sigaddset (set, signum);
kono
parents:
diff changeset
1025 }
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 int
kono
parents:
diff changeset
1028 _sigdelset (sigset_t *set, int signum)
kono
parents:
diff changeset
1029 {
kono
parents:
diff changeset
1030 return sigdelset (set, signum);
kono
parents:
diff changeset
1031 }
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 int
kono
parents:
diff changeset
1034 _sigemptyset (sigset_t *set)
kono
parents:
diff changeset
1035 {
kono
parents:
diff changeset
1036 return sigemptyset (set);
kono
parents:
diff changeset
1037 }
kono
parents:
diff changeset
1038
kono
parents:
diff changeset
1039 int
kono
parents:
diff changeset
1040 _sigfillset (sigset_t *set)
kono
parents:
diff changeset
1041 {
kono
parents:
diff changeset
1042 return sigfillset (set);
kono
parents:
diff changeset
1043 }
kono
parents:
diff changeset
1044
kono
parents:
diff changeset
1045 #include <unistd.h>
kono
parents:
diff changeset
1046 int
kono
parents:
diff changeset
1047 _getpagesize (void)
kono
parents:
diff changeset
1048 {
kono
parents:
diff changeset
1049 return getpagesize ();
kono
parents:
diff changeset
1050 }
kono
parents:
diff changeset
1051 #endif
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1052
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1053 int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1054 __gnat_name_case_equivalence ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1055 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1056 /* the values here must be synchronized with Ada.Directories.Name_Case_Kind:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1057
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1058 Unknown = 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1059 Case_Sensitive = 1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1060 Case_Insensitive = 2
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1061 Case_Preserving = 3 */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1062
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1063 #if defined (__APPLE__) || defined (WIN32)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1064 return 3;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1065 #else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1066 return 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1067 #endif
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1068 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1069