Added Paul Eggerts LocalTime patch.
authorJeremy Allison <jra@samba.org>
Fri, 29 May 1998 19:18:43 +0000 (19:18 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 29 May 1998 19:18:43 +0000 (19:18 +0000)
Jeremy.
(This used to be commit 6721c28ea6bdb5210836352bb5ffc43d787907fa)

source3/lib/time.c

index f5c40f0ba088a85ca03221fa79bbbd7014f8e3ad..1b2347a45b7a702ab0d27072c13658663541c99e 100644 (file)
@@ -79,12 +79,20 @@ static int tm_diff(struct tm *a, struct tm *b)
 }
 
 /*******************************************************************
-  return the UTC offset in seconds west of UTC
+  return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
   ******************************************************************/
 static int TimeZone(time_t t)
 {
-  struct tm tm_utc = *(gmtime(&t));
-  return tm_diff(&tm_utc,localtime(&t));
+  struct tm *tm = gmtime(&t);
+  struct tm tm_utc;
+  if (!tm)
+    return 0;
+  tm_utc = *tm;
+  tm = localtime(&t);
+  if (!tm)
+    return 0;
+  return tm_diff(&tm_utc,tm);
+
 }
 
 
@@ -217,7 +225,7 @@ static int LocTimeDiff(time_t lte)
 
 
 /****************************************************************************
-try to optimise the localtime call, it can be quite expenive on some machines
+try to optimise the localtime call, it can be quite expensive on some machines
 ****************************************************************************/
 struct tm *LocalTime(time_t *t)
 {
@@ -343,6 +351,8 @@ static uint32 make_dos_date(time_t unixdate)
   uint32 ret=0;
 
   t = LocalTime(&unixdate);
+  if (!t)
+    return 0xFFFFFFFF;
 
   ret = make_dos_date1(unixdate,t);
   ret = ((ret&0xFFFF)<<16) | make_dos_time1(unixdate,t);
@@ -457,11 +467,18 @@ return a HTTP/1.0 time string
   ***************************************************************************/
 char *http_timestring(time_t t)
 {
-       static char buf[40];
-       struct tm *tm = LocalTime(&t);
+  static fstring buf;
+  struct tm *tm = LocalTime(&t);
 
-       strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
-       return buf;
+  if (!tm)
+    slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
+  else
+#ifdef NO_STRFTIME
+  fstrcpy(buf, asctime(tm));
+#else /* NO_STRFTIME */
+  strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
+#endif /* NO_STRFTIME */
+  return buf;
 }
 
 
@@ -475,6 +492,9 @@ char *timestring(void )
   time_t t = time(NULL);
   struct tm *tm = LocalTime(&t);
 
+  if (!tm)
+    slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t);
+  else
 #ifdef NO_STRFTIME
   fstrcpy(TimeBuf, asctime(tm));
 #elif defined(CLIX) || defined(CONVEX)