Began removing $Id$ tags. This will be an ongoing process.
[citadel.git] / citadel / genstamp.c
index 627ffc19cf31aaf31f7e75179b9ef4c322378725..eb594119ab01eb8fc1f6adeb229aa1d6c2e15603 100644 (file)
@@ -1,10 +1,8 @@
 /*
- * $Id$
- *
  * Function to generate RFC822-compliant textual time/date stamp
- *
  */
 
+#include "sysdep.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -38,52 +36,55 @@ static char *weekdays[] = {
  * Supplied with a unix timestamp, generate an RFC822-compliant textual
  * time and date stamp.
  */
-void datestring(char *buf, time_t xtime, int which_format) {
-       struct tm *t;
+void datestring(char *buf, size_t n, time_t xtime, int which_format) {
+       struct tm t;
 
        long offset;
        char offsign;
 
-       t = localtime(&xtime);
+       localtime_r(&xtime, &t);
 
        /* Convert "seconds west of GMT" to "hours/minutes offset" */
+#ifdef HAVE_STRUCT_TM_TM_GMTOFF
+       offset = t.tm_gmtoff;
+#else
        offset = timezone;
+#endif
        if (offset > 0) {
-               offsign = '-';
+               offsign = '+';
        }
        else {
                offset = 0L - offset;
-               offsign = '+';
+               offsign = '-';
        }
        offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
 
        switch(which_format) {
 
                case DATESTRING_RFC822:
-                       sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
-                               weekdays[t->tm_wday],
-                               t->tm_mday,
-                               months[t->tm_mon],
-                               t->tm_year + 1900,
-                               t->tm_hour,
-                               t->tm_min,
-                               t->tm_sec,
+                       snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
+                               weekdays[t.tm_wday],
+                               t.tm_mday,
+                               months[t.tm_mon],
+                               t.tm_year + 1900,
+                               t.tm_hour,
+                               t.tm_min,
+                               t.tm_sec,
                                offsign, offset
                                );
                break;
 
                case DATESTRING_IMAP:
-                       sprintf(buf, "%02d-%s-%04d %02d:%02d:%02d %c%04ld",
-                               t->tm_mday,
-                               months[t->tm_mon],
-                               t->tm_year + 1900,
-                               t->tm_hour,
-                               t->tm_min,
-                               t->tm_sec,
+                       snprintf(buf, n, "%02d-%s-%04d %02d:%02d:%02d %c%04ld",
+                               t.tm_mday,
+                               months[t.tm_mon],
+                               t.tm_year + 1900,
+                               t.tm_hour,
+                               t.tm_min,
+                               t.tm_sec,
                                offsign, offset
                                );
                break;
 
        }
 }
-