From 22c071e51db815e36203de90720e3ddc929749f6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 7 Sep 1998 02:36:36 +0000 Subject: [PATCH] *** empty log message *** --- lib/posixtm.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/posixtm.c b/lib/posixtm.c index 699305049f..c70f8f3789 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -24,6 +24,11 @@ #include #include +#if HAVE_STRING_H +# include +#else +# include +#endif #ifdef TM_IN_SYS_TIME # include @@ -31,6 +36,18 @@ # include #endif +#include "posixtm.h" + +/* ISDIGIT differs from isdigit, as follows: + - Its arg may be any int or unsigned int; it need not be an unsigned char. + - It's guaranteed to evaluate its argument exactly once. + - It's typically faster. + Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that + only '0' through '9' are digits. Prefer ISDIGIT to isdigit unless + it's important to use the locale's definition of `digit' even when the + host does not conform to Posix. */ +#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) + /* The return value. */ static struct tm t; @@ -53,13 +70,6 @@ time_t mktime (); */ -/* FIXME: put these in posixtm.h */ -/* POSIX Date Syntax flags. */ -#define PDS_LEADING_YEAR 1 -#define PDS_TRAILING_YEAR 2 -#define PDS_CENTURY 4 -#define PDS_SECONDS 8 - static int year (const int *digit_pair, size_t n, int allow_century) { @@ -104,7 +114,7 @@ year (const int *digit_pair, size_t n, int allow_century) static int posix_time_parse (const char *s, unsigned int syntax_bits) { - const char *dot; + const char *dot = NULL; int pair[6]; int *p; int i; @@ -194,11 +204,11 @@ posix_time_parse (const char *s, unsigned int syntax_bits) /* Parse a POSIX-style date and return it, or (time_t)-1 for an error. */ -struct tm * -posixtime (const char *s) +time_t +posixtime (const char *s, unsigned int syntax_bits) { t.tm_isdst = -1; - if (posix_time_parse (s)) + if (posix_time_parse (s, syntax_bits)) return (time_t)-1; else return mktime (&t); @@ -207,9 +217,9 @@ posixtime (const char *s) /* Parse a POSIX-style date and return it, or NULL for an error. */ struct tm * -posixtm (const char *s) +posixtm (const char *s, unsigned int syntax_bits) { - if (posixtime (s) == -1) + if (posixtime (s, syntax_bits) == -1) return NULL; return &t; } -- 2.30.2