Disable tests for strdup/strndup on __hpux__
[official-gcc.git] / gcc / ada / libgnat / s-osprim__posix2008.adb
blobbbb4f14ce88e62944a90ac1bc1b2b4eee0c43330
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . O S _ P R I M I T I V E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1998-2023, Free Software Foundation, Inc. --
10 -- --
11 -- GNARL 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 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This version is for POSIX.1-2008-like operating systems
34 with System.CRTL;
35 with System.OS_Constants;
36 with System.Parameters;
37 package body System.OS_Primitives is
39 subtype int is System.CRTL.int;
41 -- ??? These definitions are duplicated from System.OS_Interface because
42 -- we don't want to depend on any package. Consider removing these
43 -- declarations in System.OS_Interface and move these ones to the spec.
45 type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
46 .. 2 ** (System.Parameters.time_t_bits - 1) - 1;
48 type timespec is record
49 tv_sec : time_t;
50 tv_nsec : Long_Integer;
51 end record;
52 pragma Convention (C, timespec);
54 function nanosleep (rqtp, rmtp : not null access timespec) return Integer;
55 pragma Import (C, nanosleep, "nanosleep");
57 -----------
58 -- Clock --
59 -----------
61 function Clock return Duration is
62 TS : aliased timespec;
63 Result : int;
65 type clockid_t is new int;
66 CLOCK_REALTIME : constant clockid_t :=
67 System.OS_Constants.CLOCK_REALTIME;
69 function clock_gettime
70 (clock_id : clockid_t;
71 tp : access timespec) return int;
72 pragma Import (C, clock_gettime, "clock_gettime");
74 begin
75 Result := clock_gettime (CLOCK_REALTIME, TS'Unchecked_Access);
76 pragma Assert (Result = 0);
77 return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
78 end Clock;
80 -----------------
81 -- To_Timespec --
82 -----------------
84 function To_Timespec (D : Duration) return timespec;
86 function To_Timespec (D : Duration) return timespec is
87 S : time_t;
88 F : Duration;
90 begin
91 S := time_t (Long_Long_Integer (D));
92 F := D - Duration (S);
94 -- If F has negative value due to a round-up, adjust for positive F
95 -- value.
97 if F < 0.0 then
98 S := S - 1;
99 F := F + 1.0;
100 end if;
102 return
103 timespec'(tv_sec => S,
104 tv_nsec => Long_Integer (Long_Long_Integer (F * 10#1#E9)));
105 end To_Timespec;
107 -----------------
108 -- Timed_Delay --
109 -----------------
111 procedure Timed_Delay
112 (Time : Duration;
113 Mode : Integer)
114 is separate;
116 ----------------
117 -- Initialize --
118 ----------------
120 procedure Initialize is
121 begin
122 null;
123 end Initialize;
125 end System.OS_Primitives;