2015-03-04 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / s-osinte-freebsd.adb
blob9ad969e8b6c034806714e1e0cc3ee8bc40f6c498
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . O S _ I N T E R F A C E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1991-2009, 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. It is --
28 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
29 -- State University (http://www.gnat.com). --
30 -- --
31 ------------------------------------------------------------------------------
33 -- This is the FreeBSD THREADS version of this package
35 with Interfaces.C; use Interfaces.C;
37 package body System.OS_Interface is
39 -----------
40 -- Errno --
41 -----------
43 function Errno return int is
44 type int_ptr is access all int;
46 function internal_errno return int_ptr;
47 pragma Import (C, internal_errno, "__error");
49 begin
50 return (internal_errno.all);
51 end Errno;
53 --------------------
54 -- Get_Stack_Base --
55 --------------------
57 function Get_Stack_Base (thread : pthread_t) return Address is
58 pragma Unreferenced (thread);
59 begin
60 return (0);
61 end Get_Stack_Base;
63 ------------------
64 -- pthread_init --
65 ------------------
67 procedure pthread_init is
68 begin
69 null;
70 end pthread_init;
72 -----------------
73 -- To_Duration --
74 -----------------
76 function To_Duration (TS : timespec) return Duration is
77 begin
78 return Duration (TS.ts_sec) + Duration (TS.ts_nsec) / 10#1#E9;
79 end To_Duration;
81 ------------------------
82 -- To_Target_Priority --
83 ------------------------
85 function To_Target_Priority
86 (Prio : System.Any_Priority) return Interfaces.C.int
88 begin
89 return Interfaces.C.int (Prio);
90 end To_Target_Priority;
92 -----------------
93 -- To_Timespec --
94 -----------------
96 function To_Timespec (D : Duration) return timespec is
97 S : time_t;
98 F : Duration;
100 begin
101 S := time_t (Long_Long_Integer (D));
102 F := D - Duration (S);
104 -- If F has negative value due to a round-up, adjust for positive F
106 if F < 0.0 then
107 S := S - 1;
108 F := F + 1.0;
109 end if;
111 return timespec'(ts_sec => S,
112 ts_nsec => long (Long_Long_Integer (F * 10#1#E9)));
113 end To_Timespec;
115 end System.OS_Interface;