I am also seeing that gmtime() is basically broken. Here is a simple test program that shows it:
test_gmtime.c
#include <stdio.h>
#include <string.h>
#include <time.h>
void test_gmtime(void)
{
struct tm tm;
struct tm *pT = NULL;
time_t utc;
memset(&tm, 0, sizeof(tm));
tm.tm_sec = 5;
tm.tm_min = 10;
tm.tm_hour = 9;
tm.tm_mday = 8; /* Day-of-month. */
tm.tm_mon = 11 - 1; /* month 0..11 */
tm.tm_year = 2016 - 1900; /* years from 1900 */
utc = mktime(&tm);
printf("ctime = %s", ctime(&utc));
pT = gmtime(&utc);
if(pT == NULL) {
printf("NULL answer\n");
} else {
printf("gmtime = %d-%d-%d %d:%d:%d\n",
pT->tm_year + 1900,
pT->tm_mon + 1,
pT->tm_mday,
pT->tm_hour,
pT->tm_min,
pT->tm_sec);
}
}
int main()
{
test_gmtime();
return 0;
}
If you compile and run this on a normal PC (e.g. Linux here, but same for windows) it works:
gcc -Wall test_gmtime.c
./a.out
ctime = Tue Nov 8 09:10:05 2016
gmtime = 2016-11-8 9:10:5
But if run in the mded compiler on a target device (in my case DISCO_L476VG) the ctime() call works fine, but the gmtime() call is broken:
ctime = Tue Nov 8 09:10:05 2016
NULL answer
Is anyone going to explain what is wrong with the function?
I am trying to get some time processing functions to work, and I am having difficulty getting gmtime to break a time_t value into a tm structure. I have the following code (having previously called set_time()):
This returns the text "gmtime fail, now is 1417599213". That value looks correct, so I don't understand why gmtime() is returning NULL. Have I called it properly, or is there some other setup that needs performing?