* str_conv.c (krb5_string_to_timestamp): Use localtime_r if available.
authorKen Raeburn <raeburn@mit.edu>
Fri, 4 Jun 2004 22:43:15 +0000 (22:43 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 4 Jun 2004 22:43:15 +0000 (22:43 +0000)
(krb5_timestamp_to_string, krb5_timestamp_to_sfstring): Likewise.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16413 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/ChangeLog
src/lib/krb5/krb/str_conv.c

index 22f6fdab31ececaa837087a24124289e7f13dcf1..48f98472d9e2fe86164ad74d85b08dec030ce568 100644 (file)
@@ -1,5 +1,9 @@
 2004-06-04  Ken Raeburn  <raeburn@mit.edu>
 
+       * str_conv.c (krb5_string_to_timestamp): Use localtime_r if
+       available.
+       (krb5_timestamp_to_string, krb5_timestamp_to_sfstring): Likewise.
+
        * parse.c (krb5_parse_name): Use assert and abort, not exit.
 
        * srv_rcache.c (krb5_get_server_rcache): Don't forget to actually
index 5fe049c1af0b04e81b620e4128ee57d5c2340357..60bb2f6f4b73932cb558814b92b3183df93d3e2f 100644 (file)
@@ -179,7 +179,11 @@ krb5_string_to_timestamp(char *string, krb5_timestamp *timestampp)
         * indicated that no guarantees are made as to preserving timebuf
         * when parsing fails
         */
+#ifdef HAVE_LOCALTIME_R
+       (void) localtime_r(&now, &timebuf);
+#else
        memcpy(&timebuf, localtime(&now), sizeof(timebuf));
+#endif
        if ((s = strptime(string, atime_format_table[i], &timebuf))
            && (s != string)) {
            /* See if at end of buffer - otherwise partial processing */
@@ -203,10 +207,16 @@ krb5_timestamp_to_string(krb5_timestamp timestamp, char *buffer, size_t buflen)
 {
     int ret;
     time_t timestamp2 = timestamp;
+    struct tm tmbuf;
     const char *fmt = "%c"; /* This is to get around gcc -Wall warning that 
                               the year returned might be two digits */
 
-    ret = strftime(buffer, buflen, fmt, localtime(&timestamp2));
+#ifdef HAVE_LOCALTIME_R
+    (void) localtime_r(&timestamp2, &tmbuf);
+#else
+    memcpy(&tmbuf, localtime(&timestamp2), sizeof(tmbuf));
+#endif
+    ret = strftime(buffer, buflen, fmt, &tmbuf);
     if (ret == 0 || ret == buflen)
        return(ENOMEM);
     return(0);
@@ -219,6 +229,7 @@ krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer, size_t buflen
     size_t i;
     size_t     ndone;
     time_t timestamp2 = timestamp;
+    struct tm tmbuf;
 
     static const char * const sftime_format_table[] = {
        "%c",                   /* Default locale-dependent date and time */
@@ -229,7 +240,11 @@ krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer, size_t buflen
     static const int sftime_format_table_nents =
        sizeof(sftime_format_table)/sizeof(sftime_format_table[0]);
 
-    tmp = localtime(&timestamp2);
+#ifdef HAVE_LOCALTIME_R
+    tmp = localtime_r(&timestamp2, &tmbuf);
+#else
+    memcpy((tmp = &tmbuf), localtime(&timestamp2), sizeof(tmbuf));
+#endif
     ndone = 0;
     for (i=0; i<sftime_format_table_nents; i++) {
        if ((ndone = strftime(buffer, buflen, sftime_format_table[i], tmp)))