1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2024, Free Software Foundation, Inc. *
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. *
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. *
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/>. *
27 * GNAT was originally developed by the GNAT team at New York University. *
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
30 ****************************************************************************/
32 /* This file contains system dependent symbols that are referenced in the
33 GNAT Run Time Library */
38 /* VxWorks 5, 6 and 7 SR0540 expose error codes that need to be handled
39 as ENOENT. On later versions:
40 - either they are defined as ENOENT (vx7r2);
41 - or the corresponding system includes are not provided (Helix Cert). */
43 #if __has_include ("dosFsLib.h")
44 /* On helix-cert, this include is only provided for RTPs. */
48 #ifndef S_dosFsLib_FILE_NOT_FOUND
49 #define S_dosFsLib_FILE_NOT_FOUND ENOENT
52 #if __has_include ("nfsLib.h")
53 /* This include is not provided for RTPs or on helix-cert. */
57 #ifndef S_nfsLib_NFSERR_NOENT
58 #define S_nfsLib_NFSERR_NOENT ENOENT
61 #include "selectLib.h"
64 # include "vwModNum.h"
66 #endif /* __vxworks */
88 #if defined (__sun__) && !defined (__vxworks)
89 /* The declaration is present in <time.h> but conditionalized
90 on a couple of macros we don't define. */
91 extern struct tm
*localtime_r(const time_t *, struct tm
*);
96 /* Don't use macros versions of this functions on VxWorks since they cause
97 imcompatible changes in some VxWorks versions */
109 (1) Opening a file with read mode fails if the file does not exist or
112 (2) Opening a file with append mode causes all subsequent writes to the
113 file to be forced to the then current end-of-file, regardless of
114 intervening calls to the fseek function.
116 (3) When a file is opened with update mode, both input and output may be
117 performed on the associated stream. However, output may not be directly
118 followed by input without an intervening call to the fflush function or
119 to a file positioning function (fseek, fsetpos, or rewind), and input
120 may not be directly followed by output without an intervening call to a
121 file positioning function, unless the input operation encounters
124 The other target dependent declarations here are for the three functions
125 __gnat_set_binary_mode, __gnat_set_text_mode and __gnat_set_mode:
127 void __gnat_set_binary_mode (int handle);
128 void __gnat_set_text_mode (int handle);
129 void __gnat_set_mode (int handle, int mode);
131 These functions have no effect in Unix (or similar systems where there is
132 no distinction between binary and text files), but in DOS (and similar
133 systems where text mode does CR/LF translation), these functions allow
134 the mode of the stream with the given handle (fileno can be used to get
135 the handle of a stream) to be changed dynamically. The returned result
136 is 0 if no error occurs and -1 if an error occurs.
138 Finally there is a boolean (character) variable
140 char __gnat_text_translation_required;
142 which is zero (false) in Unix mode, and one (true) in DOS mode, with a
143 true value indicating that text translation is required on text files
144 and that fopen supports the trailing t and b modifiers.
148 #if defined (WINNT) || defined (__CYGWIN__) || defined (__DJGPP__)
150 const char __gnat_text_translation_required
= 1;
153 #define WIN_SETMODE setmode
156 #define WIN_SETMODE _setmode
159 #if defined (__DJGPP__)
161 #define _setmode setmode
162 #endif /* __DJGPP__ */
165 __gnat_set_binary_mode (int handle
)
167 WIN_SETMODE (handle
, O_BINARY
);
171 __gnat_set_text_mode (int handle
)
173 WIN_SETMODE (handle
, O_TEXT
);
176 #if defined (__CYGWIN__) || defined (__DJGPP__)
178 __gnat_set_mode (int handle
, int mode
)
180 /* the values here must be synchronized with
181 System.File_Control_Block.Content_Encodding:
191 case 0 : setmode(handle
, O_BINARY
); break;
192 case 1 : setmode(handle
, O_TEXT
); break;
193 case 2 : setmode(handle
, O_TEXT
); break;
194 case 3 : setmode(handle
, O_TEXT
); break;
195 case 4 : setmode(handle
, O_BINARY
); break;
196 case 5 : setmode(handle
, O_BINARY
); break;
201 __gnat_set_mode (int handle
, int mode
)
203 /* the values here must be synchronized with
204 System.File_Control_Block.Content_Encodding:
214 case 0 : WIN_SETMODE (handle
, _O_BINARY
); break;
215 case 1 : WIN_SETMODE (handle
, __gnat_current_ccs_encoding
); break;
216 case 2 : WIN_SETMODE (handle
, _O_TEXT
); break;
217 case 3 : WIN_SETMODE (handle
, _O_U8TEXT
); break;
218 case 4 : WIN_SETMODE (handle
, _O_WTEXT
); break;
219 case 5 : WIN_SETMODE (handle
, _O_U16TEXT
); break;
227 __gnat_ttyname (int filedes
)
229 extern char *ttyname (int);
231 return ttyname (filedes
);
234 #endif /* __CYGWIN__ */
236 #if defined (__CYGWIN__) || defined (__MINGW32__)
237 #define WIN32_LEAN_AND_MEAN
240 int __gnat_is_windows_xp (void);
243 __gnat_is_windows_xp (void)
245 static int is_win_xp
=0, is_win_xp_checked
=0;
247 if (!is_win_xp_checked
)
249 OSVERSIONINFO version
;
251 is_win_xp_checked
= 1;
253 memset (&version
, 0, sizeof (version
));
254 version
.dwOSVersionInfoSize
= sizeof (version
);
256 is_win_xp
= GetVersionEx (&version
)
257 && version
.dwPlatformId
== VER_PLATFORM_WIN32_NT
258 && (version
.dwMajorVersion
> 5
259 || (version
.dwMajorVersion
== 5 && version
.dwMinorVersion
>= 1));
264 /* Get the bounds of the stack. The stack pointer is supposed to be
265 initialized to BASE when a thread is created and the stack can be extended
266 to LIMIT before reaching a guard page.
267 Note: for the main thread, the system automatically extend the stack, so
268 LIMIT is only the current limit. */
271 __gnat_get_stack_bounds (void **base
, void **limit
)
275 /* We know that the first field of the TEB is the TIB. */
276 tib
= (NT_TIB
*)NtCurrentTeb ();
278 *base
= tib
->StackBase
;
279 *limit
= tib
->StackLimit
;
282 #endif /* __CYGWIN__ || __MINGW32__ */
286 /* Return the name of the tty. Under windows there is no name for
287 the tty, so this function, if connected to a tty, returns the generic name
291 __gnat_ttyname (int filedes
)
293 if (isatty (filedes
))
299 #endif /* __MINGW32__ */
303 const char __gnat_text_translation_required
= 0;
305 /* These functions do nothing in non-DOS systems. */
308 __gnat_set_binary_mode (int handle ATTRIBUTE_UNUSED
)
313 __gnat_set_text_mode (int handle ATTRIBUTE_UNUSED
)
318 __gnat_set_mode (int handle ATTRIBUTE_UNUSED
, int mode ATTRIBUTE_UNUSED
)
323 __gnat_ttyname (int filedes ATTRIBUTE_UNUSED
)
325 #if defined (__vxworks)
328 extern char *ttyname (int);
330 return ttyname (filedes
);
331 #endif /* defined (__vxworks) */
335 #if defined (__linux__) || defined (__sun__) \
337 || defined (__MACHTEN__) || defined (__hpux__) || defined (_AIX) \
338 || (defined (__svr4__) && defined (__i386__)) || defined (__Lynx__) \
339 || defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
340 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
344 # include <conio.h> /* for getch(), kbhit() */
346 # include <termios.h>
351 /* Implements the common processing for getc_immediate and
352 getc_immediate_nowait. */
354 extern void getc_immediate (FILE *, int *, int *);
355 extern void getc_immediate_nowait (FILE *, int *, int *, int *);
356 extern void getc_immediate_common (FILE *, int *, int *, int *, int);
358 /* Called by Get_Immediate (Foo); */
361 getc_immediate (FILE *stream
, int *ch
, int *end_of_file
)
365 getc_immediate_common (stream
, ch
, end_of_file
, &avail
, 1);
368 /* Called by Get_Immediate (Foo, Available); */
371 getc_immediate_nowait (FILE *stream
, int *ch
, int *end_of_file
, int *avail
)
373 getc_immediate_common (stream
, ch
, end_of_file
, avail
, 0);
376 /* Called by getc_immediate () and getc_immediate_nowait () */
379 getc_immediate_common (FILE *stream
,
383 int waiting ATTRIBUTE_UNUSED
)
385 #if defined (__linux__) || defined (__sun__) \
386 || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
387 || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
388 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
389 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
394 int eof_ch
= 4; /* Ctrl-D */
395 int fd
= fileno (stream
);
396 struct termios otermios_rec
, termios_rec
;
400 tcgetattr (fd
, &termios_rec
);
401 memcpy (&otermios_rec
, &termios_rec
, sizeof (struct termios
));
403 /* Set RAW mode, with no echo */
404 termios_rec
.c_lflag
= termios_rec
.c_lflag
& ~ICANON
& ~ECHO
;
406 #if defined (__linux__) || defined (__sun__) \
407 || defined (__MACHTEN__) || defined (__hpux__) \
408 || defined (_AIX) || (defined (__svr4__) && defined (__i386__)) \
409 || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
410 || defined (__GLIBC__) || defined (__APPLE__) || defined (__DragonFly__) \
412 eof_ch
= termios_rec
.c_cc
[VEOF
];
414 /* If waiting (i.e. Get_Immediate (Char)), set MIN = 1 and wait for
415 a character forever. This doesn't seem to effect Ctrl-Z or
417 If not waiting (i.e. Get_Immediate (Char, Available)),
418 don't wait for anything but timeout immediately. */
419 termios_rec
.c_cc
[VMIN
] = waiting
;
420 termios_rec
.c_cc
[VTIME
] = 0;
422 tcsetattr (fd
, TCSANOW
, &termios_rec
);
426 /* Read is used here instead of fread, because fread doesn't
427 work on Solaris5 and Sunos4 in this situation. Maybe because we
428 are mixing calls that use file descriptors and streams. */
429 nread
= read (fd
, &c
, 1);
432 /* On Unix terminals, Ctrl-D (EOT) is an End of File. */
440 /* Everything else is ok */
441 else if (c
!= eof_ch
)
459 tcsetattr (fd
, TCSANOW
, &otermios_rec
);
464 #elif defined (__MINGW32__)
465 int fd
= fileno (stream
);
467 int eot_ch
= 4; /* Ctrl-D */
484 char_waiting
= kbhit();
486 if (char_waiting
== 1)
504 #elif defined (__vxworks)
505 /* Bit masks of file descriptors to read from. */
506 struct fd_set readFds
;
507 /* Timeout before select returns if nothing can be read. */
508 struct timeval timeOut
;
510 int fd
= fileno (stream
);
519 /* If we do not want to wait, we have to set up fd in RAW mode. This
520 should be done outside this function as setting fd in RAW mode under
521 vxWorks flushes the buffer of fd. If the RAW mode was set here, the
522 buffer would be empty and we would always return that no character
526 /* Initialization of timeOut for its use with select. */
530 /* Initialization of readFds for its use with select;
531 FD is the only file descriptor to be monitored */
533 FD_SET (fd
, &readFds
);
536 /* We do all this processing to emulate a non blocking read. */
537 readable
= select (width
, &readFds
, NULL
, NULL
, &timeOut
);
538 if (readable
== ERROR
)
539 *avail
= -1, *end_of_file
= -1;
540 /* No character available in input. */
541 else if (readable
== 0)
542 *avail
= 0, *end_of_file
= 0;
545 nread
= read (fd
, &c
, 1);
547 *avail
= 1, *end_of_file
= 0;
550 *avail
= 0, *end_of_file
= 1;
553 *avail
= -1, *end_of_file
= -1;
557 /* We have to wait until we get a character */
563 /* Save the current mode of FD. */
564 option
= ioctl (fd
, FIOGETOPTIONS
, 0);
566 /* Set FD in RAW mode. */
567 status
= ioctl (fd
, FIOSETOPTIONS
, OPT_RAW
);
570 nread
= read (fd
, &c
, 1);
572 *avail
= 1, *end_of_file
= 0;
575 *avail
= 0, *end_of_file
= 1;
576 /* Else there is an ERROR. */
579 /* Revert FD to its previous mode. */
580 status
= ioctl (fd
, FIOSETOPTIONS
, option
);
588 /* If we're not on a terminal, then we don't need any fancy processing.
589 Also this is the only thing that's left if we're not on one of the
590 supported systems; which means that for non supported systems,
591 get_immediate may wait for a carriage return on terminals. */
592 *ch
= fgetc (stream
);
606 /* The following definitions are provided in NT to support Windows based
610 #define WIN32_LEAN_AND_MEAN
613 /* Provide functions to echo the values passed to WinMain (windows bindings
614 will want to import these). We use the same names as the routines used
615 by AdaMagic for compatibility. */
617 char *rts_get_hInstance (void);
618 char *rts_get_hPrevInstance (void);
619 char *rts_get_lpCommandLine (void);
620 int rts_get_nShowCmd (void);
623 rts_get_hInstance (void)
625 return (char *)GetModuleHandleA (0);
629 rts_get_hPrevInstance (void)
635 rts_get_lpCommandLine (void)
637 return GetCommandLineA ();
641 rts_get_nShowCmd (void)
648 /* This value is returned as the time zone offset when a valid value
649 cannot be determined. It is simply a bizarre value that will never
650 occur. It is 3 days plus 73 seconds (offset is in seconds). */
652 long __gnat_invalid_tzoff
= 259273;
654 /* Definition of __gnat_localtime_r used by a-calend.adb */
656 #if defined (__MINGW32__)
658 /* Reentrant localtime for Windows. */
661 __gnat_localtime_tzoff (const OS_Time
*, const int *, long *);
663 static const unsigned long long w32_epoch_offset
= 11644473600ULL;
665 __gnat_localtime_tzoff (const OS_Time
*timer
, const int *is_historic
, long *off
)
667 TIME_ZONE_INFORMATION tzi
;
671 tzi_status
= GetTimeZoneInformation (&tzi
);
673 /* Cases where we simply want to extract the offset of the current time
674 zone, regardless of the date. A value of "0" for flag "is_historic"
675 signifies that the date is NOT historic, see the
676 body of Ada.Calendar.UTC_Time_Offset. */
678 if (*is_historic
== 0) {
681 /* The system is operating in the range covered by the StandardDate
683 if (tzi_status
== TIME_ZONE_ID_STANDARD
) {
684 *off
= *off
+ tzi
.StandardBias
;
687 /* The system is operating in the range covered by the DaylightDate
689 else if (tzi_status
== TIME_ZONE_ID_DAYLIGHT
) {
690 *off
= *off
+ tzi
.DaylightBias
;
696 /* Time zone offset calculations for a historic or future date */
702 unsigned long long ull_time
;
703 } utc_time
, local_time
;
705 SYSTEMTIME utc_sys_time
, local_sys_time
;
708 /* First convert unix time_t structure to windows FILETIME format. */
709 utc_time
.ull_time
= ((unsigned long long) *timer
+ w32_epoch_offset
)
712 /* If GetTimeZoneInformation does not return a value between 0 and 2 then
713 it means that we were not able to retrieve timezone information. Note
714 that we cannot use here FileTimeToLocalFileTime as Windows will use in
715 always in this case the current timezone setting. As suggested on MSDN
716 we use the following three system calls to get the right information.
717 Note also that starting with Windows Vista new functions are provided
718 to get timezone settings that depend on the year. We cannot use them as
719 we still support Windows XP and Windows 2003. */
721 status
= tzi_status
<= 2
722 && FileTimeToSystemTime (&utc_time
.ft_time
, &utc_sys_time
)
723 && SystemTimeToTzSpecificLocalTime (&tzi
, &utc_sys_time
, &local_sys_time
)
724 && SystemTimeToFileTime (&local_sys_time
, &local_time
.ft_time
);
726 /* An error has occurred, return invalid_tzoff */
729 *off
= __gnat_invalid_tzoff
;
732 if (local_time
.ull_time
> utc_time
.ull_time
) {
733 *off
= (long) ((local_time
.ull_time
- utc_time
.ull_time
)
737 *off
= - (long) ((utc_time
.ull_time
- local_time
.ull_time
)
744 #elif defined (__Lynx__)
746 /* On Lynx, all time values are treated in GMT */
748 /* As of LynxOS 3.1.0a patch level 040, LynuxWorks changes the
749 prototype to the C library function localtime_r from the POSIX.4
750 Draft 9 to the POSIX 1.c version. Before this change the following
751 spec is required. Only use when ___THREADS_POSIX4ad4__ is defined,
752 the Lynx convention when building against the legacy API. */
755 __gnat_localtime_tzoff (const OS_Time
*, const int *, long *);
758 __gnat_localtime_tzoff (const OS_Time
*timer
, const int *is_historic
, long *off
)
765 /* Other targets except Lynx and Windows provide a standard localtime_r */
767 #define Lock_Task system__soft_links__lock_task
768 extern void (*Lock_Task
) (void);
770 #define Unlock_Task system__soft_links__unlock_task
771 extern void (*Unlock_Task
) (void);
774 __gnat_localtime_tzoff (const OS_Time
*, const int *, long *);
777 __gnat_localtime_tzoff (const OS_Time
*timer ATTRIBUTE_UNUSED
,
778 const int *is_historic ATTRIBUTE_UNUSED
,
779 long *off ATTRIBUTE_UNUSED
)
781 struct tm tp ATTRIBUTE_UNUSED
;
782 const time_t time
= (time_t) *timer
;
784 /* AIX, HPUX, Sun Solaris */
785 #if defined (_AIX) || defined (__hpux__) || defined (__sun__)
789 localtime_r (&time
, &tp
);
790 *off
= (long) -timezone
;
794 /* Correct the offset if Daylight Saving Time is in effect */
801 #elif defined (__vxworks)
806 localtime_r (&time
, &tp
);
808 /* Try to read the environment variable TIMEZONE. The variable may not have
809 been initialize, in that case return an offset of zero (0) for UTC. */
811 char *tz_str
= getenv ("TIMEZONE");
813 if ((tz_str
== NULL
) || (*tz_str
== '\0'))
817 char *tz_start
, *tz_end
;
819 /* The format of the data contained in TIMEZONE is N::U:S:E where N is the
820 name of the time zone, U are the minutes difference from UTC, S is the
821 start of DST in mmddhh and E is the end of DST in mmddhh. Extracting
822 the value of U involves setting two pointers, one at the beginning and
823 one at the end of the value. The end pointer is then set to null in
824 order to delimit a string slice for atol to process. */
826 tz_start
= index (tz_str
, ':') + 2;
827 tz_end
= index (tz_start
, ':');
830 /* The Ada layer expects an offset in seconds. Note that we must reverse
831 the sign of the result since west is positive and east is negative on
834 *off
= -atol (tz_start
) * 60;
836 /* Correct the offset if Daylight Saving Time is in effect */
845 /* Darwin, Free BSD, Linux, where component tm_gmtoff is present in
848 #elif defined (__APPLE__) || defined (__FreeBSD__) || defined (__linux__) \
849 || defined (__GLIBC__) || defined (__DragonFly__) || defined (__OpenBSD__) \
850 || defined (__DJGPP__) || defined (__QNX__)
852 localtime_r (&time
, &tp
);
856 /* Default: treat all time values in GMT */
861 #endif /* defined(_AIX) ... */
870 /* __gnat_get_task_options is used by s-taprop.adb only for VxWorks. This
871 function returns the options to be set when creating a new task. It fetches
872 the options assigned to the current task (parent), so offering some user
873 level control over the options for a task hierarchy. It forces VX_FP_TASK
874 because it is almost always required. On processors with the SPE
875 category, VX_SPE_TASK should be used instead to enable the SPE. */
876 extern int __gnat_get_task_options (void);
879 __gnat_get_task_options (void)
883 /* Get the options for the task creator */
884 taskOptionsGet (taskIdSelf (), &options
);
886 /* Force VX_FP_TASK or VX_SPE_TASK as needed */
887 #if defined (__SPE__)
888 options
|= VX_SPE_TASK
;
890 options
|= VX_FP_TASK
;
893 /* Mask those bits that are not under user control */
894 #ifdef VX_USR_TASK_OPTIONS
895 /* O810-007, TSR 00043679:
896 Workaround a bug in Vx-7 where VX_DEALLOC_TCB == VX_PRIVATE_UMASK and:
897 - VX_DEALLOC_TCB is an internal option not to be used by users
898 - VX_PRIVATE_UMASK as a user-definable option
899 This leads to VX_USR_TASK_OPTIONS allowing 0x8000 as VX_PRIVATE_UMASK but
900 taskCreate refusing this option (VX_DEALLOC_TCB is not allowed)
902 Note that the same error occurs in both RTP and Kernel mode, but
903 VX_DEALLOC_TCB is not defined in the RTP headers, so we need to
904 explicitely check if VX_PRIVATE_UMASK has value 0x8000
906 # if defined (VX_PRIVATE_UMASK) && (0x8000 == VX_PRIVATE_UMASK)
907 options
&= ~VX_PRIVATE_UMASK
;
909 options
&= VX_USR_TASK_OPTIONS
;
917 __gnat_is_file_not_found_error (int errno_val
)
919 /* WARNING: Do not rewrite this as a switch/case statement.
920 * Some of the "cases" are duplicated in some versions of
921 * Vxworks, notably VxWorks7r2 SR0610. */
922 if (errno_val
== ENOENT
)
925 /* Starting with VxWorks 21.03, the fopen() function can set errno to
926 * ENODEV when the prefix of the path does not match any known device. */
927 else if (errno_val
== ENODEV
)
929 /* In the case of VxWorks, we also have to take into account various
930 * filesystem-specific variants of this error.
932 else if (errno_val
== S_dosFsLib_FILE_NOT_FOUND
)
934 else if (errno_val
== S_nfsLib_NFSERR_NOENT
)
936 #if defined (__RTP__)
937 /* An RTP can return an NFS file not found, and the NFS bits must
938 first be masked on to check the errno. */
939 else if (errno_val
== (M_nfsStat
| ENOENT
))
947 #if defined (__linux__)
949 /* Note well: If this code is modified, it should be tested by hand,
950 because automated testing doesn't exercise it.
953 /* HAVE_CAPABILITY is supposed to be defined if sys/capability.h exists on the
954 system where this is being compiled. If this macro is defined, we #include
955 the header. Otherwise we have the relevant declarations textually here.
958 #if defined (HAVE_CAPABILITY)
959 #include <sys/capability.h>
962 /* HAVE_CAPABILITY is not defined, so sys/capability.h does might not exist. */
964 typedef struct _cap_struct
*cap_t
;
969 #define CAP_SYS_NICE 23
971 CAP_EFFECTIVE
=0, /* Specifies the effective flag */
972 CAP_PERMITTED
=1, /* Specifies the permitted flag */
973 CAP_INHERITABLE
=2 /* Specifies the inheritable flag */
976 typedef int cap_value_t
;
978 extern cap_t
cap_get_proc(void);
979 extern int cap_get_flag(cap_t
, cap_value_t
, cap_flag_t
, cap_flag_value_t
*);
980 extern int cap_free(void *);
984 /* __gnat_has_cap_sys_nice returns 1 if the current process has the
985 CAP_SYS_NICE capability. This capability is necessary to use the
986 Ceiling_Locking policy. Returns 0 otherwise. Note that this is
987 defined only for Linux.
990 /* Define these as weak symbols, so if support for capabilities is not present,
991 programs can still link. On Ubuntu, support for capabilities can be
992 installed via "sudo apt-get --assume-yes install libcap-dev".
993 In addition, the user must link with "-lcap", or else these
994 symbols will be 0, and __gnat_has_cap_sys_nice will return 0.
997 static cap_t
cap_get_proc_weak(void)
998 __attribute__ ((weakref ("cap_get_proc")));
999 static int cap_get_flag_weak(cap_t
, cap_value_t
, cap_flag_t
, cap_flag_value_t
*)
1000 __attribute__ ((weakref ("cap_get_flag")));
1001 static int cap_free_weak(void *)
1002 __attribute__ ((weakref ("cap_free")));
1005 __gnat_has_cap_sys_nice () {
1006 /* If the address of cap_get_proc_weak is 0, this means support for
1007 capabilities is not present, so we return 0. */
1008 if (&cap_get_proc_weak
== 0)
1011 cap_t caps
= cap_get_proc_weak();
1015 cap_flag_value_t value
;
1017 if (cap_get_flag_weak(caps
, CAP_SYS_NICE
, CAP_EFFECTIVE
, &value
) == -1)
1020 if (cap_free_weak(caps
) == -1)
1023 if (value
== CAP_SET
)
1032 /* Provide extern symbols for sig* as needed by the tasking run-time, instead
1033 of static inline functions. */
1038 _sigismember (sigset_t
*set
, int signum
)
1040 return sigismember (set
, signum
);
1044 _sigaddset (sigset_t
*set
, int signum
)
1046 return sigaddset (set
, signum
);
1050 _sigdelset (sigset_t
*set
, int signum
)
1052 return sigdelset (set
, signum
);
1056 _sigemptyset (sigset_t
*set
)
1058 return sigemptyset (set
);
1062 _sigfillset (sigset_t
*set
)
1064 return sigfillset (set
);
1071 return getpagesize ();
1076 __gnat_name_case_equivalence ()
1078 /* the values here must be synchronized with Ada.Directories.Name_Case_Kind:
1082 Case_Insensitive = 2
1083 Case_Preserving = 3 */
1085 #if defined (__APPLE__) || defined (WIN32)