utils: Printf() defined time output should gmtime/localtime_r() fail
This commit is contained in:
@@ -648,21 +648,24 @@ 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)
|
||||||
|
{
|
||||||
|
if (utc)
|
||||||
|
{
|
||||||
|
ret = gmtime_r(time, &t);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = localtime_r(time, &t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
return print_in_hook(data, "--- -- --:--:--%s----",
|
return print_in_hook(data, "--- -- --:--:--%s----",
|
||||||
utc ? " UTC " : " ");
|
utc ? " UTC " : " ");
|
||||||
}
|
}
|
||||||
if (utc)
|
|
||||||
{
|
|
||||||
gmtime_r(time, &t);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
localtime_r(time, &t);
|
|
||||||
}
|
|
||||||
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,
|
||||||
t.tm_sec, utc ? " UTC " : " ", t.tm_year + 1900);
|
t.tm_sec, utc ? " UTC " : " ", t.tm_year + 1900);
|
||||||
|
|||||||
Reference in New Issue
Block a user