summaryrefslogtreecommitdiff
path: root/lib/posixtm.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-09-07 02:36:36 +0000
committerJim Meyering <jim@meyering.net>1998-09-07 02:36:36 +0000
commit981c203fabe073e95e15c4512f9b61eea2d86d1b (patch)
tree2e9bec19700c8cd5e28b14e01556a80c22bfe66f /lib/posixtm.c
parentc0385fb129d16ebf0b9655cf77a0a8ed4a2968b1 (diff)
downloadcoreutils-981c203fabe073e95e15c4512f9b61eea2d86d1b.tar.xz
*** empty log message ***
Diffstat (limited to 'lib/posixtm.c')
-rw-r--r--lib/posixtm.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/posixtm.c b/lib/posixtm.c
index 699305049..c70f8f378 100644
--- a/lib/posixtm.c
+++ b/lib/posixtm.c
@@ -24,6 +24,11 @@
#include <stdio.h>
#include <sys/types.h>
+#if HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif
#ifdef TM_IN_SYS_TIME
# include <sys/time.h>
@@ -31,6 +36,18 @@
# include <time.h>
#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;
}