]> code.citadel.org Git - citadel.git/blobdiff - citadel/genstamp.c
removed all references to sprintf from several files (not all files yet)
[citadel.git] / citadel / genstamp.c
index 1ca2752cd6f2d4527dee237807137cfed3cb9a2c..737b3fa54ebd8fdfaa8535329527776f2d0f617e 100644 (file)
@@ -5,11 +5,28 @@
  *
  */
 
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
+#define timezonevar 1
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include "genstamp.h"
 
 
@@ -27,7 +44,7 @@ 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) {
+void datestring(char *buf, size_t n, time_t xtime, int which_format) {
        struct tm *t;
 
        long offset;
@@ -36,7 +53,11 @@ void datestring(char *buf, time_t xtime, int which_format) {
        t = localtime(&xtime);
 
        /* 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 = '-';
        }
@@ -49,7 +70,7 @@ void datestring(char *buf, time_t xtime, int which_format) {
        switch(which_format) {
 
                case DATESTRING_RFC822:
-                       sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
+                       snprintf(buf, n, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
                                weekdays[t->tm_wday],
                                t->tm_mday,
                                months[t->tm_mon],
@@ -62,7 +83,7 @@ void datestring(char *buf, time_t xtime, int which_format) {
                break;
 
                case DATESTRING_IMAP:
-                       sprintf(buf, "%02d-%s-%04d %02d:%02d:%02d %c%04ld",
+                       snprintf(buf, n, "%02d-%s-%04d %02d:%02d:%02d %c%04ld",
                                t->tm_mday,
                                months[t->tm_mon],
                                t->tm_year + 1900,