public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] newlib/libc/time/strptime.c(strptime_l) add %F %s support for strptime
@ 2017-08-25 12:04 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2017-08-25 12:04 UTC (permalink / raw)
To: newlib-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=406bd10fb4c92282a340db6a7f725121d675f810
commit 406bd10fb4c92282a340db6a7f725121d675f810
Author: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
Date: Thu Aug 24 13:12:17 2017 -0600
newlib/libc/time/strptime.c(strptime_l) add %F %s support for strptime
Diff:
---
newlib/libc/time/strptime.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
index c0861eb..2ec001a 100644
--- a/newlib/libc/time/strptime.c
+++ b/newlib/libc/time/strptime.c
@@ -38,6 +38,9 @@
#include <strings.h>
#include <ctype.h>
#include <stdlib.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
#include "../locale/setlocale.h"
#define _ctloc(x) (_CurrentTimeLocale->x)
@@ -230,8 +233,15 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
buf = s;
ymd |= SET_MDAY;
break;
+ case 'F' : /* %Y-%m-%d - GNU extension */
+ s = strptime_l (buf, "%Y-%m-%d", timeptr, locale);
+ if (s == NULL || s == buf)
+ return NULL;
+ buf = s;
+ ymd |= SET_YMD;
+ break;
case 'H' :
- case 'k' :
+ case 'k' : /* hour with leading space - GNU extension */
ret = strtol_l (buf, &s, 10, locale);
if (s == buf)
return NULL;
@@ -239,7 +249,7 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
buf = s;
break;
case 'I' :
- case 'l' :
+ case 'l' : /* hour with leading space - GNU extension */
ret = strtol_l (buf, &s, 10, locale);
if (s == buf)
return NULL;
@@ -300,6 +310,26 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
return NULL;
buf = s;
break;
+ case 's' : /* seconds since Unix epoch - GNU extension */
+ {
+ long long sec;
+ time_t t;
+ int save_errno;
+
+ save_errno = errno;
+ errno = 0;
+ sec = strtoll_l (buf, &s, 10, locale);
+ t = sec;
+ if (s == buf
+ || errno != 0
+ || t != sec
+ || localtime_r (&t, timeptr) != timeptr)
+ return NULL;
+ errno = save_errno;
+ buf = s;
+ ymd |= SET_YDAY | SET_WDAY | SET_YMD;
+ break;
+ }
case 'S' :
ret = strtol_l (buf, &s, 10, locale);
if (s == buf)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-08-25 12:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25 12:04 [newlib-cygwin] newlib/libc/time/strptime.c(strptime_l) add %F %s support for strptime Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).