diff options
author | Jeremy Allison <jra@samba.org> | 2006-07-11 18:01:26 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:19:14 -0500 |
commit | fbdcf2663b56007a438ac4f0d8d82436b1bfe688 (patch) | |
tree | 4e42c1f061391cea3d640152fd240682cbf4fd9a /source3/lib/time.c | |
parent | 5bf62a0c3cc95abe918f3e772bb10e0a90fdce22 (diff) | |
download | samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.tar.gz samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.tar.xz samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.zip |
r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
to do the upper layer directories but this is what
everyone is waiting for....
Jeremy.
(This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8)
Diffstat (limited to 'source3/lib/time.c')
-rw-r--r-- | source3/lib/time.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/source3/lib/time.c b/source3/lib/time.c index 9a539d415e8..0bfdfac856b 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -635,7 +635,7 @@ char *http_timestring(time_t t) Return the date and time as a string ****************************************************************************/ -char *timestring(BOOL hires) +char *current_timestring(BOOL hires) { static fstring TimeBuf; struct timeval tp; @@ -1056,6 +1056,51 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) } #endif + +/** + Return the date and time as a string +**/ +char *timestring(TALLOC_CTX *mem_ctx, time_t t) +{ + char *TimeBuf; + char tempTime[80]; + struct tm *tm; + + tm = localtime(&t); + if (!tm) { + return talloc_asprintf(mem_ctx, + "%ld seconds since the Epoch", + (long)t); + } + +#ifdef HAVE_STRFTIME + /* some versions of gcc complain about using %c. This is a bug + in the gcc warning, not a bug in this code. See a recent + strftime() manual page for details. + */ + strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); + TimeBuf = talloc_strdup(mem_ctx, tempTime); +#else + TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); +#endif + + return TimeBuf; +} + + +/** + return a talloced string representing a NTTIME for human consumption +*/ +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) +{ + time_t t; + if (nt.low == 0 && nt.high == 0) { + return "NTTIME(0)"; + } + t = nt_time_to_unix(&nt); + return timestring(mem_ctx, t); +} + /**************************************************************************** Utility function that always returns a const string even if localtime and asctime fail. |