with System.OS_Primitives;
+with System.OS_Lib;
+
package body Ada.Calendar with
SPARK_Mode => Off
is
type int_Pointer is access all Interfaces.C.int;
type long_Pointer is access all Interfaces.C.long;
- type time_t is
- range -(2 ** (Standard'Address_Size - Integer'(1))) ..
- +(2 ** (Standard'Address_Size - Integer'(1)) - 1);
- type time_t_Pointer is access all time_t;
+ type OS_Time_Pointer is access all System.OS_Lib.OS_Time;
procedure localtime_tzoff
- (timer : time_t_Pointer;
+ (timer : OS_Time_Pointer;
is_historic : int_Pointer;
off : long_Pointer);
pragma Import (C, localtime_tzoff, "__gnat_localtime_tzoff");
Date_N : Time_Rep;
Flag : aliased Interfaces.C.int;
Offset : aliased Interfaces.C.long;
- Secs_T : aliased time_t;
+ Secs_T : aliased System.OS_Lib.OS_Time;
-- Start of processing for UTC_Time_Offset
-- Convert the date into seconds
- Secs_T := time_t (Date_N / Nano);
+ Secs_T := System.OS_Lib.To_Ada (Long_Long_Integer (Date_N / Nano));
-- Determine whether to treat the input date as historical or not. A
-- value of "0" signifies that the date is NOT historic.
------------------
-- Note: Do not use time_t in the compiler and host-based tools; instead
- -- use OS_Time. These 3 declarations are intended for use only by consumers
- -- of the GNAT.OS_Lib renaming of this package.
+ -- use OS_Time.
subtype time_t is Long_Long_Integer;
- -- C time_t can be either long or long long, but this is a subtype not used
- -- in the compiler or tools, but only for user applications, so we choose
- -- the Ada equivalent of the latter because eventually that will be the
+ -- C time_t can be either long or long long, so we choose the Ada
+ -- equivalent of the latter because eventually that will be the
-- type used out of necessity. This may affect some user code on 32-bit
-- targets that have not yet migrated to the Posix 2008 standard,
- -- particularly pre version 5 32-bit Linux.
+ -- particularly pre version 5 32-bit Linux. Do not change this
+ -- declaration without coordinating it with conversions in Ada.Calendar.
function To_C (Time : OS_Time) return time_t;
-- Convert OS_Time to C time_t type
/* Reentrant localtime for Windows. */
extern void
-__gnat_localtime_tzoff (const time_t *, const int *, long *);
+__gnat_localtime_tzoff (const OS_Time *, const int *, long *);
static const unsigned long long w32_epoch_offset = 11644473600ULL;
void
-__gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
+__gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off)
{
TIME_ZONE_INFORMATION tzi;
the Lynx convention when building against the legacy API. */
extern void
-__gnat_localtime_tzoff (const time_t *, const int *, long *);
+__gnat_localtime_tzoff (const OS_Time *, const int *, long *);
void
-__gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
+__gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off)
{
*off = 0;
}
extern void (*Unlock_Task) (void);
extern void
-__gnat_localtime_tzoff (const time_t *, const int *, long *);
+__gnat_localtime_tzoff (const OS_Time *, const int *, long *);
void
-__gnat_localtime_tzoff (const time_t *timer ATTRIBUTE_UNUSED,
+__gnat_localtime_tzoff (const OS_Time *timer ATTRIBUTE_UNUSED,
const int *is_historic ATTRIBUTE_UNUSED,
long *off ATTRIBUTE_UNUSED)
{
struct tm tp ATTRIBUTE_UNUSED;
+ const time_t time = (time_t) *timer;
/* AIX, HPUX, Sun Solaris */
#if defined (_AIX) || defined (__hpux__) || defined (__sun__)
{
(*Lock_Task) ();
- localtime_r (timer, &tp);
+ localtime_r (&time, &tp);
*off = (long) -timezone;
(*Unlock_Task) ();
{
(*Lock_Task) ();
- localtime_r (timer, &tp);
+ localtime_r (&time, &tp);
/* Try to read the environment variable TIMEZONE. The variable may not have
been initialize, in that case return an offset of zero (0) for UTC. */
|| defined (__GLIBC__) || defined (__DragonFly__) || defined (__OpenBSD__) \
|| defined (__DJGPP__) || defined (__QNX__)
{
- localtime_r (timer, &tp);
+ localtime_r (&time, &tp);
*off = tp.tm_gmtoff;
}