diff options
author | Volker Lendecke <vl@samba.org> | 2009-11-19 11:50:13 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2009-11-19 19:04:38 +0100 |
commit | d3d37acb998672dc9d2f36927151cce8393b6d44 (patch) | |
tree | 84714f51025a0c9a0f393eadbe3b97330ed7a002 /source3/lib | |
parent | d4312e776b70e63554dd31ec7da242dfcc62c137 (diff) | |
download | samba-d3d37acb998672dc9d2f36927151cce8393b6d44.tar.gz samba-d3d37acb998672dc9d2f36927151cce8393b6d44.tar.bz2 samba-d3d37acb998672dc9d2f36927151cce8393b6d44.zip |
s3: Factor timeval_string out of current_timestring()
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/time.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/source3/lib/time.c b/source3/lib/time.c index 1d2fae3d17..a418c42dd7 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -188,27 +188,21 @@ int set_server_zone_offset(time_t t) Return the date and time as a string ****************************************************************************/ -char *current_timestring(TALLOC_CTX *ctx, bool hires) +char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires) { fstring TimeBuf; - struct timeval tp; time_t t; struct tm *tm; - if (hires) { - GetTimeOfDay(&tp); - t = (time_t)tp.tv_sec; - } else { - t = time(NULL); - } + t = (time_t)tp->tv_sec; tm = localtime(&t); if (!tm) { if (hires) { slprintf(TimeBuf, sizeof(TimeBuf)-1, "%ld.%06ld seconds since the Epoch", - (long)tp.tv_sec, - (long)tp.tv_usec); + (long)tp->tv_sec, + (long)tp->tv_usec); } else { slprintf(TimeBuf, sizeof(TimeBuf)-1, @@ -222,7 +216,7 @@ char *current_timestring(TALLOC_CTX *ctx, bool hires) slprintf(TimeBuf+strlen(TimeBuf), sizeof(TimeBuf)-1 - strlen(TimeBuf), ".%06ld", - (long)tp.tv_usec); + (long)tp->tv_usec); } else { strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); } @@ -233,7 +227,7 @@ char *current_timestring(TALLOC_CTX *ctx, bool hires) sizeof(TimeBuf)-1, "%s.%06ld", asct ? asct : "unknown", - (long)tp.tv_usec); + (long)tp->tv_usec); } else { const char *asct = asctime(tm); fstrcpy(TimeBuf, asct ? asct : "unknown"); @@ -243,6 +237,13 @@ char *current_timestring(TALLOC_CTX *ctx, bool hires) return talloc_strdup(ctx, TimeBuf); } +char *current_timestring(TALLOC_CTX *ctx, bool hires) +{ + struct timeval tv; + + GetTimeOfDay(&tv); + return timeval_string(ctx, &tv, hires); +} /******************************************************************* Put a dos date into a buffer (time/date format). |