From: Ken Raeburn Date: Fri, 4 Jun 2004 22:43:15 +0000 (+0000) Subject: * str_conv.c (krb5_string_to_timestamp): Use localtime_r if available. X-Git-Tag: krb5-1.4-beta1~359 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b2140341ecfcd64da8a448d8deb89bbea0fd57bf;p=krb5.git * str_conv.c (krb5_string_to_timestamp): Use localtime_r if available. (krb5_timestamp_to_string, krb5_timestamp_to_sfstring): Likewise. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16413 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/ChangeLog b/src/lib/krb5/krb/ChangeLog index 22f6fdab3..48f98472d 100644 --- a/src/lib/krb5/krb/ChangeLog +++ b/src/lib/krb5/krb/ChangeLog @@ -1,5 +1,9 @@ 2004-06-04 Ken Raeburn + * 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 diff --git a/src/lib/krb5/krb/str_conv.c b/src/lib/krb5/krb/str_conv.c index 5fe049c1a..60bb2f6f4 100644 --- a/src/lib/krb5/krb/str_conv.c +++ b/src/lib/krb5/krb/str_conv.c @@ -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(×tamp2)); +#ifdef HAVE_LOCALTIME_R + (void) localtime_r(×tamp2, &tmbuf); +#else + memcpy(&tmbuf, localtime(×tamp2), 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(×tamp2); +#ifdef HAVE_LOCALTIME_R + tmp = localtime_r(×tamp2, &tmbuf); +#else + memcpy((tmp = &tmbuf), localtime(×tamp2), sizeof(tmbuf)); +#endif ndone = 0; for (i=0; i