utils: Printf() defined time output should gmtime/localtime_r() fail

This commit is contained in:
Martin Willi
2014-06-04 15:52:58 +02:00
parent 087e02e47e
commit 8f129319ff
+10 -7
View File
@@ -648,20 +648,23 @@ int time_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
}; };
time_t *time = *((time_t**)(args[0])); time_t *time = *((time_t**)(args[0]));
bool utc = *((int*)(args[1])); bool utc = *((int*)(args[1]));
struct tm t; struct tm t, *ret = NULL;
if (*time == UNDEFINED_TIME) if (*time != UNDEFINED_TIME)
{ {
return print_in_hook(data, "--- -- --:--:--%s----",
utc ? " UTC " : " ");
}
if (utc) if (utc)
{ {
gmtime_r(time, &t); ret = gmtime_r(time, &t);
} }
else else
{ {
localtime_r(time, &t); ret = localtime_r(time, &t);
}
}
if (ret == NULL)
{
return print_in_hook(data, "--- -- --:--:--%s----",
utc ? " UTC " : " ");
} }
return print_in_hook(data, "%s %02d %02d:%02d:%02d%s%04d", return print_in_hook(data, "%s %02d %02d:%02d:%02d%s%04d",
months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min, months[t.tm_mon], t.tm_mday, t.tm_hour, t.tm_min,