]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Update from glibc 2.1.
authorUlrich Drepper <drepper@redhat.com>
Wed, 20 May 1998 12:12:53 +0000 (12:12 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 20 May 1998 12:12:53 +0000 (12:12 +0000)
time/offtime.c

index f13c8a38ae1d7f86c9065980382595fda84ae146..a3feb8f448dca10a0aab6c955d29ce1141d91b89 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1993, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -26,15 +26,16 @@ extern const unsigned short int __mon_yday[2][13];
 
 /* Compute the `struct tm' representation of *T,
    offset OFFSET seconds east of UTC,
-   and store year, yday, mon, mday, wday, hour, min, sec into *TP.  */
-void
+   and store year, yday, mon, mday, wday, hour, min, sec into *TP.
+   Return nonzero if successful.  */
+int
 __offtime (t, offset, tp)
      const time_t *t;
      long int offset;
      struct tm *tp;
 {
-  register long int days, rem, y;
-  register const unsigned short int *ip;
+  long int days, rem, y;
+  const unsigned short int *ip;
 
   days = *t / SECS_PER_DAY;
   rem = *t % SECS_PER_DAY;
@@ -59,7 +60,8 @@ __offtime (t, offset, tp)
     tp->tm_wday += 7;
   y = 1970;
 
-#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
+#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
+#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
 
   while (days < 0 || days >= (__isleap (y) ? 366 : 365))
     {
@@ -73,11 +75,14 @@ __offtime (t, offset, tp)
       y = yg;
     }
   tp->tm_year = y - 1900;
+  if (tp->tm_year != y - 1900)
+    return 0;
   tp->tm_yday = days;
   ip = __mon_yday[__isleap(y)];
-  for (y = 11; days < ip[y]; --y)
+  for (y = 11; days < (long int) ip[y]; --y)
     continue;
   days -= ip[y];
   tp->tm_mon = y;
   tp->tm_mday = days + 1;
+  return 1;
 }