Concretize three gimple_return_ accessors
[official-gcc.git] / gcc / ada / sysdep.c
blobbdda22cc69f64ed4635bf112b0eaf8d54cc8318c
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * S Y S D E P *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2014, 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 ****************************************************************************/
32 /* This file contains system dependent symbols that are referenced in the
33 GNAT Run Time Library */
35 #ifdef __vxworks
36 #include "ioLib.h"
37 #if ! defined (VTHREADS)
38 #include "dosFsLib.h"
39 #endif
40 #if ! defined (__RTP__) && (! defined (VTHREADS) || defined (__VXWORKSMILS__))
41 # include "nfsLib.h"
42 #endif
43 #include "selectLib.h"
44 #include "vxWorks.h"
45 #include "version.h"
46 #if defined (__RTP__)
47 # include "vwModNum.h"
48 #endif /* __RTP__ */
49 #endif
51 #ifdef __ANDROID__
52 #undef linux
53 #endif
55 #ifdef IN_RTS
56 #define POSIX
57 #include "tconfig.h"
58 #include "tsystem.h"
59 #include <fcntl.h>
60 #include <sys/stat.h>
61 #ifdef VMS
62 #include <unixio.h>
63 #endif
64 #else
65 #include "config.h"
66 #include "system.h"
67 #endif
69 #include <time.h>
70 #include <errno.h>
72 #if defined (sun) && defined (__SVR4) && !defined (__vxworks)
73 /* The declaration is present in <time.h> but conditionalized
74 on a couple of macros we don't define. */
75 extern struct tm *localtime_r(const time_t *, struct tm *);
76 #endif
78 #include "adaint.h"
80 /* Don't use macros versions of this functions on VxWorks since they cause
81 imcompatible changes in some VxWorks versions */
82 #ifdef __vxworks
83 #undef getchar
84 #undef putchar
85 #undef feof
86 #undef ferror
87 #undef fileno
88 #endif
91 Notes:
93 (1) Opening a file with read mode fails if the file does not exist or
94 cannot be read.
96 (2) Opening a file with append mode causes all subsequent writes to the
97 file to be forced to the then current end-of-file, regardless of
98 intervening calls to the fseek function.
100 (3) When a file is opened with update mode, both input and output may be
101 performed on the associated stream. However, output may not be directly
102 followed by input without an intervening call to the fflush function or
103 to a file positioning function (fseek, fsetpos, or rewind), and input
104 may not be directly followed by output without an intervening call to a
105 file positioning function, unless the input operation encounters
106 end-of-file.
108 The other target dependent declarations here are for the three functions
109 __gnat_set_binary_mode, __gnat_set_text_mode and __gnat_set_mode:
111 void __gnat_set_binary_mode (int handle);
112 void __gnat_set_text_mode (int handle);
113 void __gnat_set_mode (int handle, int mode);
115 These functions have no effect in Unix (or similar systems where there is
116 no distinction between binary and text files), but in DOS (and similar
117 systems where text mode does CR/LF translation), these functions allow
118 the mode of the stream with the given handle (fileno can be used to get
119 the handle of a stream) to be changed dynamically. The returned result
120 is 0 if no error occurs and -1 if an error occurs.
122 Finally there is a boolean (character) variable
124 char __gnat_text_translation_required;
126 which is zero (false) in Unix mode, and one (true) in DOS mode, with a
127 true value indicating that text translation is required on text files
128 and that fopen supports the trailing t and b modifiers.
132 #if defined (WINNT) || defined (__CYGWIN__)
134 const char __gnat_text_translation_required = 1;
136 #ifdef __CYGWIN__
137 #define WIN_SETMODE setmode
138 #include <io.h>
139 #else
140 #define WIN_SETMODE _setmode
141 #endif
143 void
144 __gnat_set_binary_mode (int handle)
146 WIN_SETMODE (handle, O_BINARY);
149 void
150 __gnat_set_text_mode (int handle)
152 WIN_SETMODE (handle, O_TEXT);
155 void
156 __gnat_set_mode (int handle, int mode)
158 /* the values here must be synchronized with
159 System.File_Control_Block.Content_Encodding:
161 None = 0
162 Default_Text = 1
163 Text = 2
164 U8text = 3
165 Wtext = 4
166 U16text = 5 */
168 switch (mode) {
169 case 0 : WIN_SETMODE (handle, _O_BINARY); break;
170 case 1 : WIN_SETMODE (handle, CurrentCCSEncoding); break;
171 case 2 : WIN_SETMODE (handle, _O_TEXT); break;
172 case 3 : WIN_SETMODE (handle, _O_U8TEXT); break;
173 case 4 : WIN_SETMODE (handle, _O_WTEXT); break;
174 case 5 : WIN_SETMODE (handle, _O_U16TEXT); break;
178 #ifdef __CYGWIN__
180 char *
181 __gnat_ttyname (int filedes)
183 extern char *ttyname (int);
185 return ttyname (filedes);
188 #endif /* __CYGWIN__ */
190 #if defined (__CYGWIN__) || defined (__MINGW32__)
191 #include <windows.h>
193 #ifndef RTX
195 int __gnat_is_windows_xp (void);
198 __gnat_is_windows_xp (void)
200 static int is_win_xp=0, is_win_xp_checked=0;
202 if (!is_win_xp_checked)
204 OSVERSIONINFO version;
206 is_win_xp_checked = 1;
208 memset (&version, 0, sizeof (version));
209 version.dwOSVersionInfoSize = sizeof (version);
211 is_win_xp = GetVersionEx (&version)
212 && version.dwPlatformId == VER_PLATFORM_WIN32_NT
213 && (version.dwMajorVersion > 5
214 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1));
216 return is_win_xp;
219 #endif /* !RTX */
221 /* Get the bounds of the stack. The stack pointer is supposed to be
222 initialized to BASE when a thread is created and the stack can be extended
223 to LIMIT before reaching a guard page.
224 Note: for the main thread, the system automatically extend the stack, so
225 LIMIT is only the current limit. */
227 void
228 __gnat_get_stack_bounds (void **base, void **limit)
230 NT_TIB *tib;
232 /* We know that the first field of the TEB is the TIB. */
233 tib = (NT_TIB *)NtCurrentTeb ();
235 *base = tib->StackBase;
236 *limit = tib->StackLimit;
239 #endif /* __CYGWIN__ || __MINGW32__ */
241 #ifdef __MINGW32__
243 /* Return the name of the tty. Under windows there is no name for
244 the tty, so this function, if connected to a tty, returns the generic name
245 "console". */
247 char *
248 __gnat_ttyname (int filedes)
250 if (isatty (filedes))
251 return "console";
252 else
253 return NULL;
256 #endif /* __MINGW32__ */
258 #else
260 const char __gnat_text_translation_required = 0;
262 /* These functions do nothing in non-DOS systems. */
264 void
265 __gnat_set_binary_mode (int handle ATTRIBUTE_UNUSED)
269 void
270 __gnat_set_text_mode (int handle ATTRIBUTE_UNUSED)
274 void
275 __gnat_set_mode (int handle ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED)
279 char *
280 __gnat_ttyname (int filedes)
282 #if defined (__vxworks) || defined (__nucleus)
283 return "";
284 #else
285 extern char *ttyname (int);
287 return ttyname (filedes);
288 #endif /* defined (__vxworks) || defined (__nucleus) */
290 #endif
292 #if defined (linux) || defined (sun) \
293 || defined (WINNT) \
294 || defined (__MACHTEN__) || defined (__hpux__) || defined (_AIX) \
295 || (defined (__svr4__) && defined (i386)) || defined (__Lynx__) \
296 || defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
297 || defined (__GLIBC__) || defined (__APPLE__)
299 # ifdef __MINGW32__
300 # if OLD_MINGW
301 # include <termios.h>
302 # else
303 # include <conio.h> /* for getch(), kbhit() */
304 # endif
305 # else
306 # include <termios.h>
307 # endif
309 #else
310 # if defined (VMS)
311 extern char *decc$ga_stdscr;
312 static int initted = 0;
313 # endif
314 #endif
316 /* Implements the common processing for getc_immediate and
317 getc_immediate_nowait. */
319 extern void getc_immediate (FILE *, int *, int *);
320 extern void getc_immediate_nowait (FILE *, int *, int *, int *);
321 extern void getc_immediate_common (FILE *, int *, int *, int *, int);
323 /* Called by Get_Immediate (Foo); */
325 void
326 getc_immediate (FILE *stream, int *ch, int *end_of_file)
328 int avail;
330 getc_immediate_common (stream, ch, end_of_file, &avail, 1);
333 /* Called by Get_Immediate (Foo, Available); */
335 void
336 getc_immediate_nowait (FILE *stream, int *ch, int *end_of_file, int *avail)
338 getc_immediate_common (stream, ch, end_of_file, avail, 0);
341 /* Called by getc_immediate () and getc_immediate_nowait () */
343 void
344 getc_immediate_common (FILE *stream,
345 int *ch,
346 int *end_of_file,
347 int *avail,
348 int waiting ATTRIBUTE_UNUSED)
350 #if defined (linux) || defined (sun) \
351 || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
352 || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
353 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
354 || defined (__GLIBC__) || defined (__APPLE__)
355 char c;
356 int nread;
357 int good_one = 0;
358 int eof_ch = 4; /* Ctrl-D */
359 int fd = fileno (stream);
360 struct termios otermios_rec, termios_rec;
362 if (isatty (fd))
364 tcgetattr (fd, &termios_rec);
365 memcpy (&otermios_rec, &termios_rec, sizeof (struct termios));
367 /* Set RAW mode, with no echo */
368 termios_rec.c_lflag = termios_rec.c_lflag & ~ICANON & ~ECHO;
370 #if defined(linux) || defined (sun) \
371 || defined (__MACHTEN__) || defined (__hpux__) \
372 || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
373 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
374 || defined (__GLIBC__) || defined (__APPLE__)
375 eof_ch = termios_rec.c_cc[VEOF];
377 /* If waiting (i.e. Get_Immediate (Char)), set MIN = 1 and wait for
378 a character forever. This doesn't seem to effect Ctrl-Z or
379 Ctrl-C processing.
380 If not waiting (i.e. Get_Immediate (Char, Available)),
381 don't wait for anything but timeout immediately. */
382 termios_rec.c_cc[VMIN] = waiting;
383 termios_rec.c_cc[VTIME] = 0;
384 #endif
385 tcsetattr (fd, TCSANOW, &termios_rec);
387 while (! good_one)
389 /* Read is used here instead of fread, because fread doesn't
390 work on Solaris5 and Sunos4 in this situation. Maybe because we
391 are mixing calls that use file descriptors and streams. */
392 nread = read (fd, &c, 1);
393 if (nread > 0)
395 /* On Unix terminals, Ctrl-D (EOT) is an End of File. */
396 if (c == eof_ch)
398 *avail = 0;
399 *end_of_file = 1;
400 good_one = 1;
403 /* Everything else is ok */
404 else if (c != eof_ch)
406 *avail = 1;
407 *end_of_file = 0;
408 good_one = 1;
412 else if (! waiting)
414 *avail = 0;
415 *end_of_file = 0;
416 good_one = 1;
418 else
419 good_one = 0;
422 tcsetattr (fd, TCSANOW, &otermios_rec);
423 *ch = c;
426 else
427 #elif defined (VMS)
428 int fd = fileno (stream);
430 if (isatty (fd))
432 if (initted == 0)
434 decc$bsd_initscr ();
435 initted = 1;
438 decc$bsd_cbreak ();
439 *ch = decc$bsd_wgetch (decc$ga_stdscr);
441 if (*ch == 4)
442 *end_of_file = 1;
443 else
444 *end_of_file = 0;
446 *avail = 1;
447 decc$bsd_nocbreak ();
449 else
450 #elif defined (__MINGW32__)
451 int fd = fileno (stream);
452 int char_waiting;
453 int eot_ch = 4; /* Ctrl-D */
455 if (isatty (fd))
457 if (waiting)
459 *ch = getch ();
461 if (*ch == eot_ch)
462 *end_of_file = 1;
463 else
464 *end_of_file = 0;
466 *avail = 1;
468 else /* ! waiting */
470 char_waiting = kbhit();
472 if (char_waiting == 1)
474 *avail = 1;
475 *ch = getch ();
477 if (*ch == eot_ch)
478 *end_of_file = 1;
479 else
480 *end_of_file = 0;
482 else
484 *avail = 0;
485 *end_of_file = 0;
489 else
490 #elif defined (__vxworks)
491 /* Bit masks of file descriptors to read from. */
492 struct fd_set readFds;
493 /* Timeout before select returns if nothing can be read. */
494 struct timeval timeOut;
495 char c;
496 int fd = fileno (stream);
497 int nread;
498 int option;
499 int readable;
500 int status;
501 int width;
503 if (isatty (fd))
505 /* If we do not want to wait, we have to set up fd in RAW mode. This
506 should be done outside this function as setting fd in RAW mode under
507 vxWorks flushes the buffer of fd. If the RAW mode was set here, the
508 buffer would be empty and we would always return that no character
509 is available */
510 if (! waiting)
512 /* Initialization of timeOut for its use with select. */
513 timeOut.tv_sec = 0;
514 timeOut.tv_usec = 0;
516 /* Initialization of readFds for its use with select;
517 FD is the only file descriptor to be monitored */
518 FD_ZERO (&readFds);
519 FD_SET (fd, &readFds);
520 width = 2;
522 /* We do all this processing to emulate a non blocking read. */
523 readable = select (width, &readFds, NULL, NULL, &timeOut);
524 if (readable == ERROR)
525 *avail = -1, *end_of_file = -1;
526 /* No character available in input. */
527 else if (readable == 0)
528 *avail = 0, *end_of_file = 0;
529 else
531 nread = read (fd, &c, 1);
532 if (nread > 0)
533 *avail = 1, *end_of_file = 0;
534 /* End Of File. */
535 else if (nread == 0)
536 *avail = 0, *end_of_file = 1;
537 /* Error. */
538 else
539 *avail = -1, *end_of_file = -1;
543 /* We have to wait until we get a character */
544 else
546 *avail = -1;
547 *end_of_file = -1;
549 /* Save the current mode of FD. */
550 option = ioctl (fd, FIOGETOPTIONS, 0);
552 /* Set FD in RAW mode. */
553 status = ioctl (fd, FIOSETOPTIONS, OPT_RAW);
554 if (status != -1)
556 nread = read (fd, &c, 1);
557 if (nread > 0)
558 *avail = 1, *end_of_file = 0;
559 /* End of file. */
560 else if (nread == 0)
561 *avail = 0, *end_of_file = 1;
562 /* Else there is an ERROR. */
565 /* Revert FD to its previous mode. */
566 status = ioctl (fd, FIOSETOPTIONS, option);
569 *ch = c;
571 else
572 #endif
574 /* If we're not on a terminal, then we don't need any fancy processing.
575 Also this is the only thing that's left if we're not on one of the
576 supported systems; which means that for non supported systems,
577 get_immediate may wait for a carriage return on terminals. */
578 *ch = fgetc (stream);
579 if (feof (stream))
581 *end_of_file = 1;
582 *avail = 0;
584 else
586 *end_of_file = 0;
587 *avail = 1;
592 /* The following definitions are provided in NT to support Windows based
593 Ada programs. */
595 #ifdef WINNT
596 #include <windows.h>
598 /* Provide functions to echo the values passed to WinMain (windows bindings
599 will want to import these). We use the same names as the routines used
600 by AdaMagic for compatibility. */
602 char *rts_get_hInstance (void);
603 char *rts_get_hPrevInstance (void);
604 char *rts_get_lpCommandLine (void);
605 int rts_get_nShowCmd (void);
607 char *
608 rts_get_hInstance (void)
610 return (char *)GetModuleHandleA (0);
613 char *
614 rts_get_hPrevInstance (void)
616 return 0;
619 char *
620 rts_get_lpCommandLine (void)
622 return GetCommandLineA ();
626 rts_get_nShowCmd (void)
628 return 1;
631 #endif /* WINNT */
632 #ifdef VMS
634 /* This gets around a problem with using the old threads library on VMS 7.0. */
636 extern long get_gmtoff (void);
638 long
639 get_gmtoff (void)
641 time_t t;
642 struct tm *ts;
644 t = time ((time_t) 0);
645 ts = localtime (&t);
646 return ts->tm_gmtoff;
648 #endif
650 /* This value is returned as the time zone offset when a valid value
651 cannot be determined. It is simply a bizarre value that will never
652 occur. It is 3 days plus 73 seconds (offset is in seconds). */
654 long __gnat_invalid_tzoff = 259273;
656 /* Definition of __gnat_localtime_r used by a-calend.adb */
658 #if defined (__MINGW32__)
660 #ifdef CERT
662 /* For the Cert run times on native Windows we use dummy functions
663 for locking and unlocking tasks since we do not support multiple
664 threads on this configuration (Cert run time on native Windows). */
666 void dummy (void) {}
668 void (*Lock_Task) () = &dummy;
669 void (*Unlock_Task) () = &dummy;
671 #else
673 #define Lock_Task system__soft_links__lock_task
674 extern void (*Lock_Task) (void);
676 #define Unlock_Task system__soft_links__unlock_task
677 extern void (*Unlock_Task) (void);
679 #endif
681 /* Reentrant localtime for Windows. */
683 extern void
684 __gnat_localtime_tzoff (const time_t *, const int *, long *);
686 static const unsigned long long w32_epoch_offset = 11644473600ULL;
687 void
688 __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
690 TIME_ZONE_INFORMATION tzi;
692 BOOL rtx_active;
693 DWORD tzi_status;
695 #ifdef RTX
696 rtx_active = 1;
697 #else
698 rtx_active = 0;
699 #endif
701 (*Lock_Task) ();
703 tzi_status = GetTimeZoneInformation (&tzi);
705 /* Processing for RTX targets or cases where we simply want to extract the
706 offset of the current time zone, regardless of the date. A value of "0"
707 for flag "is_historic" signifies that the date is NOT historic, see the
708 body of Ada.Calendar.UTC_Time_Offset. */
710 if (rtx_active || *is_historic == 0) {
711 *off = tzi.Bias;
713 /* The system is operating in the range covered by the StandardDate
714 member. */
715 if (tzi_status == TIME_ZONE_ID_STANDARD) {
716 *off = *off + tzi.StandardBias;
719 /* The system is operating in the range covered by the DaylightDate
720 member. */
721 else if (tzi_status == TIME_ZONE_ID_DAYLIGHT) {
722 *off = *off + tzi.DaylightBias;
725 *off = *off * -60;
728 /* Time zone offset calculations for a historic or future date */
730 else {
731 union
733 FILETIME ft_time;
734 unsigned long long ull_time;
735 } utc_time, local_time;
737 SYSTEMTIME utc_sys_time, local_sys_time;
738 BOOL status;
740 /* First convert unix time_t structure to windows FILETIME format. */
741 utc_time.ull_time = ((unsigned long long) *timer + w32_epoch_offset)
742 * 10000000ULL;
744 /* If GetTimeZoneInformation does not return a value between 0 and 2 then
745 it means that we were not able to retrieve timezone information. Note
746 that we cannot use here FileTimeToLocalFileTime as Windows will use in
747 always in this case the current timezone setting. As suggested on MSDN
748 we use the following three system calls to get the right information.
749 Note also that starting with Windows Vista new functions are provided
750 to get timezone settings that depend on the year. We cannot use them as
751 we still support Windows XP and Windows 2003. */
753 status = (tzi_status >= 0 && tzi_status <= 2)
754 && FileTimeToSystemTime (&utc_time.ft_time, &utc_sys_time)
755 && SystemTimeToTzSpecificLocalTime (&tzi, &utc_sys_time, &local_sys_time)
756 && SystemTimeToFileTime (&local_sys_time, &local_time.ft_time);
758 /* An error has occurred, return invalid_tzoff */
760 if (!status) {
761 *off = __gnat_invalid_tzoff;
763 else {
764 if (local_time.ull_time > utc_time.ull_time) {
765 *off = (long) ((local_time.ull_time - utc_time.ull_time)
766 / 10000000ULL);
768 else {
769 *off = - (long) ((utc_time.ull_time - local_time.ull_time)
770 / 10000000ULL);
775 (*Unlock_Task) ();
778 #else
780 /* On Lynx, all time values are treated in GMT */
782 #if defined (__Lynx__)
784 /* As of LynxOS 3.1.0a patch level 040, LynuxWorks changes the
785 prototype to the C library function localtime_r from the POSIX.4
786 Draft 9 to the POSIX 1.c version. Before this change the following
787 spec is required. Only use when ___THREADS_POSIX4ad4__ is defined,
788 the Lynx convention when building against the legacy API. */
790 extern void
791 __gnat_localtime_tzoff (const time_t *, const int *, long *);
793 void
794 __gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
796 *off = 0;
799 #else
801 /* VMS does not need __gnat_localtime_tzoff */
803 #if defined (VMS)
805 /* Other targets except Lynx, VMS and Windows provide a standard localtime_r */
807 #else
809 #define Lock_Task system__soft_links__lock_task
810 extern void (*Lock_Task) (void);
812 #define Unlock_Task system__soft_links__unlock_task
813 extern void (*Unlock_Task) (void);
815 extern void
816 __gnat_localtime_tzoff (const time_t *, const int *, long *);
818 void
819 __gnat_localtime_tzoff (const time_t *timer ATTRIBUTE_UNUSED,
820 const int *is_historic ATTRIBUTE_UNUSED,
821 long *off ATTRIBUTE_UNUSED)
823 struct tm tp ATTRIBUTE_UNUSED;
825 /* AIX, HPUX, Sun Solaris */
826 #if defined (_AIX) || defined (__hpux__) || defined (sun)
828 (*Lock_Task) ();
830 localtime_r (timer, &tp);
831 *off = (long) -timezone;
833 (*Unlock_Task) ();
835 /* Correct the offset if Daylight Saving Time is in effect */
837 if (tp.tm_isdst > 0)
838 *off = *off + 3600;
841 /* VxWorks */
842 #elif defined (__vxworks)
843 #include <stdlib.h>
845 (*Lock_Task) ();
847 localtime_r (timer, &tp);
849 /* Try to read the environment variable TIMEZONE. The variable may not have
850 been initialize, in that case return an offset of zero (0) for UTC. */
852 char *tz_str = getenv ("TIMEZONE");
854 if ((tz_str == NULL) || (*tz_str == '\0'))
855 *off = 0;
856 else
858 char *tz_start, *tz_end;
860 /* The format of the data contained in TIMEZONE is N::U:S:E where N is the
861 name of the time zone, U are the minutes difference from UTC, S is the
862 start of DST in mmddhh and E is the end of DST in mmddhh. Extracting
863 the value of U involves setting two pointers, one at the beginning and
864 one at the end of the value. The end pointer is then set to null in
865 order to delimit a string slice for atol to process. */
867 tz_start = index (tz_str, ':') + 2;
868 tz_end = index (tz_start, ':');
869 tz_end = '\0';
871 /* The Ada layer expects an offset in seconds. Note that we must reverse
872 the sign of the result since west is positive and east is negative on
873 VxWorks targets. */
875 *off = -atol (tz_start) * 60;
877 /* Correct the offset if Daylight Saving Time is in effect */
879 if (tp.tm_isdst > 0)
880 *off = *off + 3600;
883 (*Unlock_Task) ();
886 /* Darwin, Free BSD, Linux, where component tm_gmtoff is present in
887 struct tm */
889 #elif defined (__APPLE__) || defined (__FreeBSD__) || defined (linux) \
890 || defined (__GLIBC__)
892 localtime_r (timer, &tp);
893 *off = tp.tm_gmtoff;
896 /* Default: treat all time values in GMT */
898 #else
899 *off = 0;
901 #endif
904 #endif
905 #endif
906 #endif
908 #ifdef __vxworks
910 #include <taskLib.h>
912 /* __gnat_get_task_options is used by s-taprop.adb only for VxWorks. This
913 function returns the options to be set when creating a new task. It fetches
914 the options assigned to the current task (parent), so offering some user
915 level control over the options for a task hierarchy. It forces VX_FP_TASK
916 because it is almost always required. On processors with the SPE
917 category, VX_SPE_TASK should be used instead to enable the SPE. */
918 extern int __gnat_get_task_options (void);
921 __gnat_get_task_options (void)
923 int options;
925 /* Get the options for the task creator */
926 taskOptionsGet (taskIdSelf (), &options);
928 /* Force VX_FP_TASK or VX_SPE_TASK as needed */
929 #if defined (__SPE__)
930 options |= VX_SPE_TASK;
931 #else
932 options |= VX_FP_TASK;
933 #endif
935 /* Mask those bits that are not under user control */
936 #ifdef VX_USR_TASK_OPTIONS
937 return options & VX_USR_TASK_OPTIONS;
938 #else
939 return options;
940 #endif
943 #endif
946 __gnat_is_file_not_found_error (int errno_val) {
947 switch (errno_val) {
948 case ENOENT:
949 #ifdef __vxworks
950 /* In the case of VxWorks, we also have to take into account various
951 * filesystem-specific variants of this error.
953 #if ! defined (VTHREADS) && (_WRS_VXWORKS_MAJOR < 7)
954 case S_dosFsLib_FILE_NOT_FOUND:
955 #endif
956 #if ! defined (__RTP__) && (! defined (VTHREADS) || defined (__VXWORKSMILS__))
957 case S_nfsLib_NFSERR_NOENT:
958 #endif
959 #if defined (__RTP__)
960 /* An RTP can return an NFS file not found, and the NFS bits must
961 first be masked on to check the errno. */
962 case M_nfsStat | ENOENT:
963 #endif
964 #endif
965 return 1;
967 default:
968 return 0;
972 #ifdef __ANDROID__
974 /* Provide extern symbols for sig* as needed by the tasking run-time, instead
975 of static inline functions. */
977 #include <signal.h>
980 _sigismember (sigset_t *set, int signum)
982 return sigismember (set, signum);
986 _sigaddset (sigset_t *set, int signum)
988 return sigaddset (set, signum);
992 _sigdelset (sigset_t *set, int signum)
994 return sigdelset (set, signum);
998 _sigemptyset (sigset_t *set)
1000 return sigemptyset (set);
1004 _sigfillset (sigset_t *set)
1006 return sigfillset (set);
1009 #include <unistd.h>
1011 _getpagesize (void)
1013 return getpagesize ();
1015 #endif