public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Cygwin strptime() is missing "%s" which strftime() has
@ 2017-07-24  9:21 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2017-07-24 10:53 ` Corinna Vinschen
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2017-07-24  9:21 UTC (permalink / raw)
  To: cygwin

> But that's just scanning a decimal integer to time_t.

It's not a question of whether I can or can't convert a string into an integer, rather it's a question about portability of code that uses %s for both functions and expects it to work unchanged in the Cygwin environment.  Also, strptime() was designed to be a reversal to strftime() (from the man-pages: the  strptime() function is the converse function to strftime(3)) so both are supposed to "understand" the same basic set of formats.  Because of Cygwin's strptime() missing "%s", the following also does not work even from command line:

$ date +"%s" | strptime "%s"
strptime: cannot make sense of `1500861577' using the given input formats

Thank you,

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: Cygwin strptime() is missing "%s" which strftime() has
@ 2017-07-24 21:48 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2017-07-24 22:12 ` Eric Blake
  0 siblings, 1 reply; 16+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2017-07-24 21:48 UTC (permalink / raw)
  To: cygwin

> then its use of %s in either of those functions constitutes a _bug_

Oh really?  Is that why "%s" was added to Cygwin's strftime() lately?

Thanks again for your input.

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: Cygwin strptime() is missing "%s" which strftime() has
@ 2017-07-24 19:51 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  0 siblings, 0 replies; 16+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2017-07-24 19:51 UTC (permalink / raw)
  To: cygwin

> Demand.  I patches strftime to add %s because Coreutils wanted it.  But
> coreutils doesn't use strptime, so I had no reason to add it.

Well, I was bringing up a point of API inconsistency, hoping that it'd serve as an
implicit request for an improvement so that strptime() gets its "%s"...

Maybe coreutils did not need "%s" for strptime, but dateutils certainly do, as:

> date +"%s" | strptime "%s"

does not work on Cygwin.  That looks odd.

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: Cygwin strptime() is missing "%s" which strftime() has
@ 2017-07-24 13:54 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2017-07-24 17:02 ` Eric Blake
  0 siblings, 1 reply; 16+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2017-07-24 13:54 UTC (permalink / raw)
  To: cygwin

> > > But that's just scanning a decimal integer to time_t.
> > 
> > It's not a question of whether I can or can't convert a string into an
> > integer, rather it's a question about portability of code that uses %s

> I see your point but... "portability" is kind of the wrong expression
> here.  If you have portability in mind, you should *not* use %s at all.

The point is, if I can use "%s" with strftime() on Cygwin, then I should be able to use "%s" with strptime(),
but currently there's a disconcert with that.  Indeed, "%s" is a GNU extension yet it has been on Linux for years,
so why not here but only 50%?

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Cygwin strptime() is missing "%s" which strftime() has
@ 2017-07-23 11:38 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2017-07-23 21:18 ` Kaz Kylheku
  0 siblings, 1 reply; 16+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2017-07-23 11:38 UTC (permalink / raw)
  To: cygwin

Hello,

It looks like Cygwin implementation of strptime(3) cannot understand the "%s" format (seconds since Jan 1, 1970 UTC), which strftime() can.

When I test the same code of Linux, it appears to work correctly.

Cygwin:
$ gcc -Wall -o timetest timetest.c
$ ./timetest
1500755837 -> 1500755837
Cannot convert string

Linux:

$ gcc -Wall -o timetest timetest.c
$ ./timetest
1500755887 -> 1500755887
1500755887 -> 1500755887, unconverted: ""

Anton Lavrentiev
Contractor NIH/NLM/NCBI

$ cat timetest.c
#define _XOPEN_SOURCE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main()
{
    time_t now = time(0);
    struct tm tm = *localtime(&now);
    char str[80], *s;
    size_t n = strftime(str, sizeof(str), "%s", &tm);
    if (!n) {
        printf("Cannot convert time");
        return 1;
    }
    assert(n == strlen(str));
    printf("%lu -> %s\n", (unsigned long) now, str);
    memset(&tm, 0, sizeof(tm));
    if (!(s = strptime(str, "%s", &tm))) {
        printf("Cannot convert string");
        return 1;
    }
    now = mktime(&tm);
    printf("%s -> %lu, unconverted: \"%s\"\n", str, (unsigned long) now, s);
    return 0;    
}


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-08-30  0:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-24  9:21 Cygwin strptime() is missing "%s" which strftime() has Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2017-07-24 10:53 ` Corinna Vinschen
2017-07-24 21:02 ` Kaz Kylheku
2017-07-24 21:28 ` Hans-Bernhard Bröker
2017-07-24 23:18   ` Brian Inglis
2017-07-24 23:31     ` Kaz Kylheku
2017-07-25 18:27       ` Brian Inglis
2017-08-30  0:25         ` Brian Inglis
  -- strict thread matches above, loose matches on Subject: below --
2017-07-24 21:48 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2017-07-24 22:12 ` Eric Blake
2017-07-24 22:51   ` Brian Inglis
2017-07-24 19:51 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2017-07-24 13:54 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2017-07-24 17:02 ` Eric Blake
2017-07-23 11:38 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2017-07-23 21:18 ` Kaz Kylheku

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).