Module Name: src
Committed By: ginsbach
Date: Sun May 24 02:25:43 UTC 2009
Modified Files:
src/lib/libc/time: strptime.3 strptime.c
Log Message:
Add %s to strptime(3) to make symmetric with strftime(3).
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/time/strptime.3
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/time/strptime.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/time/strptime.3
diff -u src/lib/libc/time/strptime.3:1.25 src/lib/libc/time/strptime.3:1.26
--- src/lib/libc/time/strptime.3:1.25 Fri May 1 21:34:45 2009
+++ src/lib/libc/time/strptime.3 Sun May 24 02:25:43 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: strptime.3,v 1.25 2009/05/01 21:34:45 wiz Exp $
+.\" $NetBSD: strptime.3,v 1.26 2009/05/24 02:25:43 ginsbach Exp $
.\"
.\" Copyright (c) 1997, 1998, 2008 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -164,6 +164,14 @@
.It Cm \&%S
the seconds [0,61];
leading zeros are permitted but not required.
+.It Cm \&%s
+the number of seconds since the Epoch, UTC (see
+.Xr mktime 3 ) .
+.Po
+A
+.Nx
+extension.
+.Pc
.It Cm \&%t
any white-space, including none.
.It Cm \&%T
Index: src/lib/libc/time/strptime.c
diff -u src/lib/libc/time/strptime.c:1.32 src/lib/libc/time/strptime.c:1.33
--- src/lib/libc/time/strptime.c:1.32 Fri May 1 20:15:05 2009
+++ src/lib/libc/time/strptime.c Sun May 24 02:25:43 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: strptime.c,v 1.32 2009/05/01 20:15:05 ginsbach Exp $ */
+/* $NetBSD: strptime.c,v 1.33 2009/05/24 02:25:43 ginsbach Exp $ */
/*-
* Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.32 2009/05/01 20:15:05 ginsbach Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.33 2009/05/24 02:25:43 ginsbach Exp $");
#endif
#include "namespace.h"
@@ -250,6 +250,36 @@
LEGAL_ALT(ALT_O);
continue;
+#ifndef TIME_MAX
+#define TIME_MAX INT64_MAX
+#endif
+ case 's': /* seconds since the epoch */
+ {
+ time_t sse = 0;
+ uint64_t rulim = TIME_MAX;
+
+ if (*bp < '0' || *bp > '9') {
+ bp = NULL;
+ continue;
+ }
+
+ do {
+ sse *= 10;
+ sse += *bp++ - '0';
+ rulim /= 10;
+ } while ((sse * 10 <= TIME_MAX) &&
+ rulim && *bp >= '0' && *bp <= '9');
+
+ if (sse < 0 || (uint64_t)sse > TIME_MAX) {
+ bp = NULL;
+ continue;
+ }
+
+ if (localtime_r(&sse, tm) == NULL)
+ bp = NULL;
+ }
+ continue;
+
case 'U': /* The week of year, beginning on sunday. */
case 'W': /* The week of year, beginning on monday. */
/*