From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr@ncbi.nlm.nih.gov>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: Cygwin strptime() is missing "%s" which strftime() has
Date: Sun, 23 Jul 2017 11:38:00 -0000 [thread overview]
Message-ID: <BN3PR09MB0340BFF87B6B3E7A100C1A8EA5A50@BN3PR09MB0340.namprd09.prod.outlook.com> (raw)
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
next reply other threads:[~2017-07-22 20:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-23 11:38 Lavrentiev, Anton (NIH/NLM/NCBI) [C] [this message]
2017-07-23 21:18 ` Kaz Kylheku
2017-07-24 9:21 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
2017-07-24 13:54 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2017-07-24 17:02 ` Eric Blake
2017-07-24 19:51 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
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
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=BN3PR09MB0340BFF87B6B3E7A100C1A8EA5A50@BN3PR09MB0340.namprd09.prod.outlook.com \
--to=lavr@ncbi.nlm.nih.gov \
--cc=cygwin@cygwin.com \
/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).