]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: Factor timeval_string out of current_timestring()
authorVolker Lendecke <vl@samba.org>
Thu, 19 Nov 2009 10:50:13 +0000 (11:50 +0100)
committerVolker Lendecke <vl@samba.org>
Thu, 19 Nov 2009 18:04:38 +0000 (19:04 +0100)
source3/include/proto.h
source3/lib/time.c

index 9450140b9074c834ec8a23f33f9e5b28065100b8..cad865197444fee9230bd0ec37d1de40e5f5113c 100644 (file)
@@ -1025,6 +1025,7 @@ bool nt_time_is_zero(const NTTIME *nt);
 time_t generalized_to_unix_time(const char *str);
 int get_server_zone_offset(void);
 int set_server_zone_offset(time_t t);
+char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires);
 char *current_timestring(TALLOC_CTX *ctx, bool hires);
 void srv_put_dos_date(char *buf,int offset,time_t unixdate);
 void srv_put_dos_date2(char *buf,int offset, time_t unixdate);
index 1d2fae3d171eed846a1905869461cb3ab36d3844..a418c42dd76747ebc433ad74fc8acfcf10c25610 100644 (file)
@@ -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).