* Fail when LOGGER_TEST_TIMEOFDAY is set to an invalid value
* Fail with return -1 and errno, the same as normal gettimeofday()
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
char *str = getenv("LOGGER_TEST_TIMEOFDAY");
uintmax_t sec, usec;
- if (str && sscanf(str, "%ju.%ju", &sec, &usec) == 2) {
+ if (str) {
+ if (sscanf(str, "%ju.%ju", &sec, &usec) != 2)
+ goto err;
+
tv->tv_sec = sec;
tv->tv_usec = usec;
- return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL;
+
+ if (tv->tv_sec >= 0 && tv->tv_usec >= 0)
+ return 0;
+ else
+ goto err;
}
return gettimeofday(tv, tz);
+
+err:
+ errno = EINVAL;
+ return -1;
}
static inline char *logger_xgethostname(void)