From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH] newlib/libc/time/strptime.c(strptime_l) add strptime %F %s
Date: Thu, 24 Aug 2017 08:50:00 -0000 [thread overview]
Message-ID: <20170824084416.GA29964@calimero.vinschen.de> (raw)
In-Reply-To: <d83734da-28aa-05c0-75d7-dc9c4d28802c@SystematicSw.ab.ca>
[-- Attachment #1: Type: text/plain, Size: 3444 bytes --]
Hi Brian,
On Aug 23 12:59, Brian Inglis wrote:
> On 2017-08-21 03:01, Corinna Vinschen wrote:
> > Oh, right! I forget about it *blush*
>
> Attached patch to support %F and %s in newlib libc time strptime.c strptime_l().
>
> In case the issue comes up, if the user wants to support %s as in date(1) with a
> preceding @ flag, they just have to include that verbatim before the format as
> in "@%s".
>
> Is there any way to test this newlib function on a Cygwin platform?
> I don't have access to a supported platform.
>
> Similar patch submitted for Cygwin %s.
>
> --
> Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
> From 8913eb99285915fef945767340b226002a4c9502 Mon Sep 17 00:00:00 2001
> From: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
> Date: Tue, 22 Aug 2017 15:06:02 -0600
> Subject: [PATCH] newlib/libc/time/strptime.c(strptime_l) add strptime %F %s
>
> ---
> newlib/libc/time/strptime.c | 35 +++++++++++++++++++++++++++++++++--
> 1 file changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
> index c0861eb87..233658406 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,17 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
> buf = s;
> ymd |= SET_MDAY;
> break;
> + case 'F' : /* %Y-%m-%d - GNU extension */
> + fprintf( stderr, "fmt %s buf %s\n", format, buf);
> + s = strptime_l (buf, "%Y-%m-%d", timeptr, locale);
> + fprintf( stderr, "fmt %s buf %s s %s\n", format, buf, s);
Debugging residue?
> + 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 +251,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 +312,25 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
> return NULL;
> buf = s;
> break;
> + case 's' : { /* seconds since Unix epoch - GNU extension */
Opening brace on next line, please, indented as the closing brace.
> + long long sec;
> + time_t t;
> + int errno_save;
> +
> + errno_save = 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 = errno_save;
> + buf = s;
> + ymd |= SET_YDAY | SET_WDAY | SET_YMD;
> + break;
> + }
> case 'S' :
> ret = strtol_l (buf, &s, 10, locale);
> if (s == buf)
> --
> 2.14.0
Other than the above, looks good.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2017-08-24 8:44 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <BY1PR09MB0343663DE41D927E67CF0CCEA5BB0@BY1PR09MB0343.namprd09.prod.outlook.com>
[not found] ` <acc19ec5-055b-1bd4-997d-a247755163bf@SystematicSw.ab.ca>
2017-07-24 20:42 ` Cygwin strptime() is missing "%s" which strftime() has Brian Inglis
2017-07-24 21:36 ` Craig Howland
2017-07-24 23:04 ` Brian Inglis
2017-07-25 9:19 ` Corinna Vinschen
2017-07-25 9:16 ` Corinna Vinschen
2017-07-25 16:47 ` Brian Inglis
2017-07-25 17:38 ` Craig Howland
2017-07-25 18:52 ` Corinna Vinschen
2017-07-25 20:13 ` Brian Inglis
2017-07-26 10:49 ` Corinna Vinschen
2017-07-26 17:27 ` Brian Inglis
2017-07-26 19:34 ` Corinna Vinschen
2017-07-28 20:50 ` Brian Inglis
2017-07-31 9:55 ` Corinna Vinschen
2017-08-18 18:53 ` Corinna Vinschen
2017-08-18 19:38 ` Brian Inglis
2017-08-18 19:38 ` Brian Inglis
2017-08-18 20:01 ` Brian Inglis
2017-08-19 14:01 ` Brian Inglis
2017-08-21 3:09 ` Brian Inglis
2017-08-21 9:10 ` Corinna Vinschen
2017-08-24 2:14 ` [PATCH] newlib/libc/time/strptime.c(strptime_l) add strptime %F %s Brian Inglis
2017-08-24 8:50 ` Corinna Vinschen [this message]
2017-08-25 5:30 ` Brian Inglis
2017-08-25 12:06 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170824084416.GA29964@calimero.vinschen.de \
--to=vinschen@redhat.com \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).