r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / lib / time.c
index 9a539d415e880414c2991b86234d2facc61c77ff..0bfdfac856bca89b605136e00a2e8840c65711f7 100644 (file)
@@ -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.