summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-05-29 19:18:43 +0000
committerJeremy Allison <jra@samba.org>1998-05-29 19:18:43 +0000
commit3c77f88d455ca10ec406d3afdb68dcdf458c8760 (patch)
treef4ea703a323e30dcebc6b617ab05fa30b0113c75 /source3/lib
parenta10b9ab2b9b8dcb0c994a80e6e3deae359912f57 (diff)
downloadsamba-3c77f88d455ca10ec406d3afdb68dcdf458c8760.tar.gz
samba-3c77f88d455ca10ec406d3afdb68dcdf458c8760.tar.bz2
samba-3c77f88d455ca10ec406d3afdb68dcdf458c8760.zip
Added Paul Eggerts LocalTime patch.
Jeremy. (This used to be commit 6721c28ea6bdb5210836352bb5ffc43d787907fa)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/time.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/source3/lib/time.c b/source3/lib/time.c
index f5c40f0ba0..1b2347a45b 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -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)