This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Cygwin strptime() is missing "%s" which strftime() has


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]