[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH]: strptime module
From: |
Paul Eggert |
Subject: |
Re: [PATCH]: strptime module |
Date: |
Mon, 29 Jan 2007 15:14:52 -0800 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
Thanks. I installed these further patches to try to keep this module
in sync with POSIX and glibc as much as possible. I haven't tested
this on a Windows platform, though; please let me know if there are
any problems.
2007-01-29 Paul Eggert <address@hidden>
* lib/strptime.h (strptime): Use 'restrict' for args where
POSIX requires this.
* lib/strptime.c (strptime): Likewise.
Change license notice from LGPL to GPL, since gnulib-tool will
change this as needed.
Include <config.h> if _LIBC is not defined, not if HAVE_CONFIG_H is
defined.
Include "strptime.h" first, to check interface.
Do not #undef _LIBC and _NL_CURRENT.
Do not include <stdlib.h>; no longer needed.
Include "time_r.h" and declare ptime_locale_status
only if _LIBC is not defined.
(__P): Remove unused macro.
(match_string): Bring back glibc version, but use it only if _LIBC
is defined.
(__strptime_internal): Compile tm_gmtoff code if _LIBC is defined, too.
Remove unnecessary assertion and abort() call.
Use #ifdef _NL_CURRENT rather than #if 0, for benefit of glibc.
* m4/strptime.m4: Fix serial number comment.
(gl_FUNC_STRPTIME): Require AC_C_RESTRICT, gl_TM_GMTOFF.
* modules/strptime (Files): Add m4/tm_gmtoff.m4.
(Depends-on): Add time_r.
Index: lib/strptime.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/strptime.h,v
retrieving revision 1.2
diff -u -p -r1.2 strptime.h
--- lib/strptime.h 29 Jan 2007 17:33:13 -0000 1.2
+++ lib/strptime.h 29 Jan 2007 23:12:51 -0000
@@ -23,7 +23,8 @@
#if ! HAVE_STRPTIME
/* See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/strptime.html>. */
-extern char *strptime (const char *s, const char *format, struct tm *tm);
+extern char *strptime (const char *restrict s, const char *restrict format,
+ struct tm *restrict tm);
#endif
#endif /* GNULIB_STRPTIME_H_ */
Index: lib/strptime.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/strptime.c,v
retrieving revision 1.1
diff -u -p -r1.1 strptime.c
--- lib/strptime.c 29 Jan 2007 17:21:16 -0000 1.1
+++ lib/strptime.c 29 Jan 2007 23:12:52 -0000
@@ -1,29 +1,25 @@
-/* Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
+ 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 GNU C Library is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-#ifdef HAVE_CONFIG_H
+#ifndef _LIBC
# include <config.h>
+# include "strptime.h"
#endif
-#undef _LIBC
-#undef _NL_CURRENT
-
-#include <sys/time.h>
#include <assert.h>
#include <ctype.h>
#ifdef _LIBC
@@ -38,29 +34,25 @@
# include "../locale/localeinfo.h"
#endif
-#include <stdlib.h>
-#include "strptime.h"
-#include "time_r.h"
-
-
+#ifndef _LIBC
+# include "time_r.h"
enum ptime_locale_status { not, loc, raw };
-
-
-#ifndef __P
-# if defined __GNUC__ || (defined __STDC__ && __STDC__)
-# define __P(args) args
-# else
-# define __P(args) ()
-# endif /* GCC. */
-#endif /* Not __P. */
+#endif
#define match_char(ch1, ch2) if (ch1 != ch2) return NULL
-
+#if defined _LIBC && defined __GNUC__ && __GNUC__ >= 2
+# define match_string(cs1, s2) \
+ ({ size_t len = strlen (cs1);
\
+ int result = __strncasecmp_l ((cs1), (s2), len, locale) == 0; \
+ if (result) (s2) += len; \
+ result; })
+#else
+/* Oh come on. Get a reasonable compiler. */
# define match_string(cs1, s2) \
(strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))
-
+#endif
/* We intentionally do not use isdigit() for testing because this will
lead to problems with the wide character version. */
#define get_number(from, to, n) \
@@ -271,7 +263,7 @@ __strptime_internal (rp, fmt, tm, decide
have_wday = want_xday = have_yday = have_mon = have_mday = have_uweek = 0;
have_wweek = 0;
-
+
while (*fmt != '\0')
{
/* A white space in the format string matches 0 more or white
@@ -703,11 +695,11 @@ __strptime_internal (rp, fmt, tm, decide
}
if (val > 1200)
return NULL;
-#ifdef HAVE_TM_GMTOFF
+#if defined _LIBC || HAVE_TM_GMTOFF
tm->tm_gmtoff = (val * 3600) / 100;
if (neg)
tm->tm_gmtoff = -tm->tm_gmtoff;
-#endif
+#endif
}
break;
case 'E':
@@ -1036,11 +1028,9 @@ __strptime_internal (rp, fmt, tm, decide
tm->tm_year = (century - 19) * 100;
}
- assert(era_cnt == -1);
if (era_cnt != -1)
{
- abort();
-#if 0
+#ifdef _NL_CURRENT
era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG);
if (era == NULL)
return NULL;
@@ -1126,9 +1116,9 @@ __strptime_internal (rp, fmt, tm, decide
char *
strptime (buf, format, tm LOCALE_PARAM)
- const char *buf;
- const char *format;
- struct tm *tm;
+ const char *restrict buf;
+ const char *restrict format;
+ struct tm *restrict tm;
LOCALE_PARAM_DECL
{
enum ptime_locale_status decided;
@@ -1144,4 +1134,3 @@ strptime (buf, format, tm LOCALE_PARAM)
#ifdef _LIBC
weak_alias (__strptime_l, strptime_l)
#endif
-
Index: m4/strptime.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/strptime.m4,v
retrieving revision 1.1
diff -u -p -r1.1 strptime.m4
--- m4/strptime.m4 29 Jan 2007 17:21:16 -0000 1.1
+++ m4/strptime.m4 29 Jan 2007 23:12:52 -0000
@@ -1,10 +1,12 @@
-# strtol.m4 serial 4
-dnl Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+# strptime.m4 serial 2
+dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_STRPTIME],
[
+ AC_REQUIRE([AC_C_RESTRICT])
AC_REPLACE_FUNCS(strptime)
+ AC_REQUIRE([gl_TM_GMTOFF])
])
Index: modules/strptime
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/strptime,v
retrieving revision 1.2
diff -u -p -r1.2 strptime
--- modules/strptime 29 Jan 2007 17:33:13 -0000 1.2
+++ modules/strptime 29 Jan 2007 23:12:52 -0000
@@ -5,12 +5,14 @@ Files:
lib/strptime.h
lib/strptime.c
m4/strptime.m4
+m4/tm_gmtoff.m4
Depends-on:
sys_time
string
strcase
stdbool
+time_r
configure.ac:
gl_FUNC_STRPTIME
@@ -25,4 +27,3 @@ LGPL
Maintainer:
glibc
-