summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2007-06-29 02:32:02 +0000
committerKen Raeburn <raeburn@mit.edu>2007-06-29 02:32:02 +0000
commite3e5b00bee940b94c4c6299d096e105336c4596b (patch)
treee96cfd9756af7ddee7f4de112c5e1df4128ef2e1 /src/lib
parent0d5aa03bb1256279569d8e825e3a7531b2dd2f32 (diff)
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
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/krb5/krb/str_conv.c24
1 files 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<atime_format_table_nents; i++) {
/* We reset every time throughout the loop as the manual page
* 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
+ timebuf = timebuf2;
if ((s = strptime(string, atime_format_table[i], &timebuf))
&& (s != string)) {
/* See if at end of buffer - otherwise partial processing */