X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fposixtm.c;h=5a839d6765d221367784bb74f35a60b44cdfb1c1;hb=c6ad67bb80efa455e52904f98af0c8c4ec4f36ee;hp=5273a71f44711f570102770dab134b96953097fb;hpb=267a39bafd249d7eb9c37df06dc6defcf41cb343;p=gnulib.git diff --git a/lib/posixtm.c b/lib/posixtm.c index 5273a71f4..5a839d676 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -1,7 +1,7 @@ /* Parse dates for touch and date. - Copyright (C) 1989, 1990, 1991, 1998, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation Inc. + Copyright (C) 1989, 1990, 1991, 1998, 2000, 2001, 2002, 2003, 2004, + 2005, 2006 Free Software Foundation Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,9 +20,7 @@ /* Yacc-based version written by Jim Kingdon and David MacKenzie. Rewritten by Jim Meyering. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include @@ -44,11 +42,11 @@ #endif /* 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. + - Its arg may be any int or unsigned int; it need not be an unsigned char + or EOF. - It's typically faster. POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to - ISDIGIT_LOCALE unless it's important to use the locale's definition + 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 int) (c) - '0' <= 9) @@ -62,8 +60,8 @@ time_t mktime (); (PDS_LEADING_YEAR | PDS_CENTURY | PDS_SECONDS) touch mmddhhmm[YY] FILE... (obsoleted by POSIX 1003.1-2001) - 8 or 10 digits - (PDS_TRAILING_YEAR) + 8 or 10 digits, YY (if present) must be in the range 69-99 + (PDS_TRAILING_YEAR | PDS_PRE_2000) date mmddhhmm[[CC]YY] 8, 10, or 12 digits @@ -72,7 +70,7 @@ time_t mktime (); */ static int -year (struct tm *tm, const int *digit_pair, size_t n, int allow_century) +year (struct tm *tm, const int *digit_pair, size_t n, unsigned int syntax_bits) { switch (n) { @@ -82,11 +80,15 @@ year (struct tm *tm, const int *digit_pair, size_t n, int allow_century) POSIX requires that 00-68 be interpreted as 2000-2068, and that 69-99 be interpreted as 1969-1999. */ if (digit_pair[0] <= 68) - tm->tm_year += 100; + { + if (syntax_bits & PDS_PRE_2000) + return 1; + tm->tm_year += 100; + } break; case 2: - if (!allow_century) + if (! (syntax_bits & PDS_CENTURY)) return 1; tm->tm_year = digit_pair[0] * 100 + digit_pair[1] - 1900; break; @@ -148,7 +150,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) p = pair; if (syntax_bits & PDS_LEADING_YEAR) { - if (year (tm, p, len - 4, syntax_bits & PDS_CENTURY)) + if (year (tm, p, len - 4, syntax_bits)) return 1; p += len - 4; len = 4; @@ -164,7 +166,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) /* Handle any trailing year. */ if (syntax_bits & PDS_TRAILING_YEAR) { - if (year (tm, p, len, syntax_bits & PDS_CENTURY)) + if (year (tm, p, len, syntax_bits)) return 1; } @@ -193,18 +195,18 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) bool posixtime (time_t *p, const char *s, unsigned int syntax_bits) { - struct tm tm0; - struct tm tm1; - struct tm const *tm; - time_t t; - + struct tm tm0 #ifdef lint /* Placate gcc-4's -Wuninitialized. - posix_time_parse fails to set tm0.tm_year only when it returns + posix_time_parse fails to set all of tm0 only when it returns nonzero (due to year() returning nonzero), and in that case, this code doesn't use the tm0 at all. */ - tm0.tm_year = 0; + = { 0, } #endif + ; + struct tm tm1; + struct tm const *tm; + time_t t; if (posix_time_parse (&tm0, s, syntax_bits)) return false; @@ -329,6 +331,6 @@ main (void) /* Local Variables: -compile-command: "gcc -DTEST_POSIXTIME -DHAVE_CONFIG_H -I.. -g -O -Wall -W posixtm.c" +compile-command: "gcc -DTEST_POSIXTIME -g -O -Wall -W posixtm.c" End: */