X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fposixtm.c;h=fff53f50b95bac8df3f651e2539f2f761f0e4589;hb=2f2f93bfb6e0991467a287c1f4a3e0c13b227ef1;hp=7ddf182ff7345631b1d4bb7d7f641940dcfd49cc;hpb=24ae20fb048992858350c0884b5553c7b76a1bdc;p=gnulib.git diff --git a/lib/posixtm.c b/lib/posixtm.c index 7ddf182ff..fff53f50b 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -1,10 +1,12 @@ /* Parse dates for touch and date. - Copyright (C) 1989, 1990, 1991, 1998, 2000-2003 Free Software Foundation Inc. - This program is free software; you can redistribute it and/or modify + Copyright (C) 1989, 1990, 1991, 1998, 2000, 2001, 2002, 2003, 2004, + 2005, 2006, 2007 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,40 +14,32 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + along with this program. If not, see . */ /* Yacc-based version written by Jim Kingdon and David MacKenzie. Rewritten by Jim Meyering. */ -#ifdef HAVE_CONFIG_H -# include -#endif +#include -#include +#include "posixtm.h" #include #include #include #include -#ifdef TM_IN_SYS_TIME -# include -#else -# include +#if USE_UNLOCKED_IO +# include "unlocked-io.h" #endif -#include "posixtm.h" -#include "unlocked-io.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. + - 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) (c) - '0' <= 9) +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) time_t mktime (); @@ -57,8 +51,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 @@ -67,7 +61,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) { @@ -77,11 +71,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; @@ -113,7 +111,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) const char *dot = NULL; int pair[6]; int *p; - unsigned int i; + size_t i; size_t s_len = strlen (s); size_t len = (((syntax_bits & PDS_SECONDS) && (dot = strchr (s, '.'))) @@ -143,7 +141,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; @@ -159,7 +157,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; } @@ -188,7 +186,15 @@ 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 tm0 +#ifdef lint + /* Placate gcc-4's -Wuninitialized. + 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. */ + = { 0, } +#endif + ; struct tm tm1; struct tm const *tm; time_t t; @@ -304,7 +310,7 @@ main (void) { printf ("%-15s %2u ", time_str, syntax_bits); if (posixtime (&t, time_str, syntax_bits)) - printf ("%12ld %s", (long) t, ctime (&t)); + printf ("%12ld %s", (long int) t, ctime (&t)); else printf ("%12s %s", "*", "*\n"); } @@ -316,6 +322,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: */