OSDN Git Service

PR other/52438
[pf3gnuchains/gcc-fork.git] / gcc / ada / sysdep.c
index 2b99a32..bfe7bce 100644 (file)
@@ -6,7 +6,7 @@
  *                                                                          *
  *                          C Implementation File                           *
  *                                                                          *
- *         Copyright (C) 1992-2011, Free Software Foundation, Inc.          *
+ *         Copyright (C) 1992-2012, Free Software Foundation, Inc.          *
  *                                                                          *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -644,71 +644,94 @@ extern void (*Unlock_Task) (void);
 /* Reentrant localtime for Windows. */
 
 extern void
-__gnat_localtime_tzoff (const time_t *, long *);
+__gnat_localtime_tzoff (const time_t *, const int *, long *);
 
 static const unsigned long long w32_epoch_offset = 11644473600ULL;
 void
-__gnat_localtime_tzoff (const time_t *timer, long *off)
+__gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
 {
-  union
-  {
-    FILETIME ft_time;
-    unsigned long long ull_time;
-  } utc_time, local_time;
-
-  SYSTEMTIME utc_sys_time, local_sys_time;
   TIME_ZONE_INFORMATION tzi;
 
-  BOOL  status = 1;
+  BOOL  rtx_active;
   DWORD tzi_status;
 
-  (*Lock_Task) ();
-
 #ifdef RTX
+  rtx_active = 1;
+#else
+  rtx_active = 0;
+#endif
+
+  (*Lock_Task) ();
 
   tzi_status = GetTimeZoneInformation (&tzi);
-  *off = tzi.Bias;
-  if (tzi_status == TIME_ZONE_ID_STANDARD)
-     /* The system is operating in the range covered by the StandardDate
-        member. */
-     *off = *off + tzi.StandardBias;
-  else if (tzi_status == TIME_ZONE_ID_DAYLIGHT)
-     /* The system is operating in the range covered by the DaylightDate
-        member. */
-     *off = *off + tzi.DaylightBias;
-  *off = *off * -60;
 
-#else
+  /* Processing for RTX targets or cases where we simply want to extract the
+     offset of the current time zone, regardless of the date. */
 
-  /* First convert unix time_t structure to windows FILETIME format.  */
-  utc_time.ull_time = ((unsigned long long) *timer + w32_epoch_offset)
-                      * 10000000ULL;
+  if (rtx_active || !is_historic) {
+    *off = tzi.Bias;
 
-  tzi_status = GetTimeZoneInformation (&tzi);
+    /* The system is operating in the range covered by the StandardDate
+       member. */
+    if (tzi_status == TIME_ZONE_ID_STANDARD) {
+       *off = *off + tzi.StandardBias;
+    }
 
-  /* If GetTimeZoneInformation does not return a value between 0 and 2 then
-     it means that we were not able to retrieve timezone informations.
-     Note that we cannot use here FileTimeToLocalFileTime as Windows will use
-     in always in this case the current timezone setting. As suggested on
-     MSDN we use the following three system calls to get the right information.
-     Note also that starting with Windows Vista new functions are provided to
-     get timezone settings that depend on the year. We cannot use them as we
-     still support Windows XP and Windows 2003.  */
-  status = (tzi_status >= 0 && tzi_status <= 2)
-     && FileTimeToSystemTime (&utc_time.ft_time, &utc_sys_time)
-     && SystemTimeToTzSpecificLocalTime (&tzi, &utc_sys_time, &local_sys_time)
-     && SystemTimeToFileTime (&local_sys_time, &local_time.ft_time);
-
-  if (!status)
-     /* An error occurs so return invalid_tzoff.  */
-     *off = __gnat_invalid_tzoff;
-  else
-     if (local_time.ull_time > utc_time.ull_time)
-        *off = (long) ((local_time.ull_time - utc_time.ull_time) / 10000000ULL);
-     else
-        *off = - (long) ((utc_time.ull_time - local_time.ull_time) / 10000000ULL);
+    /* The system is operating in the range covered by the DaylightDate
+       member. */
+    else if (tzi_status == TIME_ZONE_ID_DAYLIGHT) {
+       *off = *off + tzi.DaylightBias;
+    }
 
-#endif
+    *off = *off * -60;
+  }
+
+  /* Time zone offset calculations for a historic or future date */
+
+  else {
+    union
+    {
+      FILETIME ft_time;
+      unsigned long long ull_time;
+    } utc_time, local_time;
+
+    SYSTEMTIME utc_sys_time, local_sys_time;
+    BOOL status;
+
+    /* First convert unix time_t structure to windows FILETIME format.  */
+    utc_time.ull_time = ((unsigned long long) *timer + w32_epoch_offset)
+                        * 10000000ULL;
+
+    /* If GetTimeZoneInformation does not return a value between 0 and 2 then
+       it means that we were not able to retrieve timezone informations. Note
+       that we cannot use here FileTimeToLocalFileTime as Windows will use in
+       always in this case the current timezone setting. As suggested on MSDN
+       we use the following three system calls to get the right information.
+       Note also that starting with Windows Vista new functions are provided
+       to get timezone settings that depend on the year. We cannot use them as
+       we still support Windows XP and Windows 2003.  */
+
+    status = (tzi_status >= 0 && tzi_status <= 2)
+      && FileTimeToSystemTime (&utc_time.ft_time, &utc_sys_time)
+      && SystemTimeToTzSpecificLocalTime (&tzi, &utc_sys_time, &local_sys_time)
+      && SystemTimeToFileTime (&local_sys_time, &local_time.ft_time);
+
+    /* An error has occured, return invalid_tzoff */
+
+    if (!status) {
+      *off = __gnat_invalid_tzoff;
+    }
+    else {
+      if (local_time.ull_time > utc_time.ull_time) {
+        *off = (long) ((local_time.ull_time - utc_time.ull_time)
+               / 10000000ULL);
+      }
+      else {
+        *off = - (long) ((utc_time.ull_time - local_time.ull_time)
+               / 10000000ULL);
+      }
+    }
+  }
 
   (*Unlock_Task) ();
 }
@@ -726,10 +749,10 @@ __gnat_localtime_tzoff (const time_t *timer, long *off)
    the Lynx convention when building against the legacy API. */
 
 extern void
-__gnat_localtime_tzoff (const time_t *, long *);
+__gnat_localtime_tzoff (const time_t *, const int *, long *);
 
 void
-__gnat_localtime_tzoff (const time_t *timer, long *off)
+__gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
 {
   *off = 0;
 }
@@ -751,10 +774,10 @@ extern void (*Lock_Task) (void);
 extern void (*Unlock_Task) (void);
 
 extern void
-__gnat_localtime_tzoff (const time_t *, long *);
+__gnat_localtime_tzoff (const time_t *, const int *, long *);
 
 void
-__gnat_localtime_tzoff (const time_t *timer, long *off)
+__gnat_localtime_tzoff (const time_t *timer, const int *is_historic, long *off)
 {
   struct tm tp;
 
@@ -850,7 +873,7 @@ __gnat_localtime_tzoff (const time_t *timer, long *off)
    the options assigned to the current task (parent), so offering some user
    level control over the options for a task hierarchy. It forces VX_FP_TASK
    because it is almost always required. On processors with the SPE
-   category, VX_SPE_TASK is needed to enable the SPE. */
+   category, VX_SPE_TASK should be used instead to enable the SPE. */
 extern int __gnat_get_task_options (void);
 
 int
@@ -861,10 +884,11 @@ __gnat_get_task_options (void)
   /* Get the options for the task creator */
   taskOptionsGet (taskIdSelf (), &options);
 
-  /* Force VX_FP_TASK because it is almost always required */
-  options |= VX_FP_TASK;
-#if defined (__SPE__) && (! defined (__VXWORKSMILS__))
+  /* Force VX_FP_TASK or VX_SPE_TASK as needed */
+#if defined (__SPE__)
   options |= VX_SPE_TASK;
+#else
+  options |= VX_FP_TASK;
 #endif
 
   /* Mask those bits that are not under user control */