From e3e5b00bee940b94c4c6299d096e105336c4596b Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Fri, 29 Jun 2007 02:32:02 +0000 Subject: [PATCH] Define a localtime_r wrapper around localtime if the system doesn't provide localtime_r, instead of handling it in-line. Check for error indication from localtime_r. Call localtime_r only once instead of each time around the loop. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19655 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/krb/str_conv.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/krb5/krb/str_conv.c b/src/lib/krb5/krb/str_conv.c index f080c8f4f..d0a11db28 100644 --- a/src/lib/krb5/krb/str_conv.c +++ b/src/lib/krb5/krb/str_conv.c @@ -1,7 +1,7 @@ /* * lib/kadm/str_conv.c * - * Copyright 1995, 1999 by the Massachusetts Institute of Technology. + * Copyright 1995, 1999, 2007 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -148,11 +148,23 @@ extern char *strptime (const char *, const char *, static char *strptime (const char *, const char *, struct tm *); #endif +#ifndef HAVE_LOCALTIME_R +static inline struct tm * +localtime_r(const time_t *t, struct tm *buf) +{ + struct tm *tm = localtime(t); + if (tm == NULL) + return NULL; + *buf = *tm; + return buf; +} +#endif + krb5_error_code KRB5_CALLCONV krb5_string_to_timestamp(char *string, krb5_timestamp *timestampp) { int i; - struct tm timebuf; + struct tm timebuf, timebuf2; time_t now, ret_time; char *s; static const char * const atime_format_table[] = { @@ -175,16 +187,14 @@ krb5_string_to_timestamp(char *string, krb5_timestamp *timestampp) now = time((time_t *) NULL); + if (localtime_r(&now, &timebuf2) == NULL) + return EINVAL; for (i=0; i