This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Cygwin strptime() is missing "%s" which strftime() has
- From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr at ncbi dot nlm dot nih dot gov>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Sat, 22 Jul 2017 20:48:26 +0000
- Subject: Cygwin strptime() is missing "%s" which strftime() has
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=lavr at ncbi dot nlm dot nih dot gov;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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