I'm using strptime(3)
to parse a string representing a date:
#include <time.h>
#include <stdio.h>
int main () {
struct tm t;
strptime("2015-04-19 12:00:00", "%F %T", &t); /* Sunday */
printf("%d\n", t.tm_wday); /* Should print 0 */
return 0;
}
That date is a Sunday, according to the output of cal -y 2015
. But when I compile this on OSX (presumably with clang) it prints 6
:
$ gcc timetest.c ; ./a.out
6
whereas on Debian it prints the (correct) 0
:
$ gcc timetest.c ; ./a.out
0
Any explanation for the difference?
UPDATE
Here is the same program, except that t
is initialised with a valid time and I'm reporting the return value of strptime()
:
#include <time.h>
#include <stdio.h>
int main () {
time_t epoch = 0;
struct tm t;
char *ret;
t = *localtime(&epoch);
ret = strptime("2015-04-19 12:00:00", "%F %T", &t); /* Sunday */
printf("%d\n", t.tm_wday); /* Should print 0 */
printf("strptime() returned %p (%d)\n", ret, *ret);
return 0;
}
Here is the output:
$ gcc timetest.c ; ./a.out
6
strptime() returned 0x10c72af83 (0)
Here is the clang
version I use:
$ clang -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin