Do proper error handling in print_time()

This commit is contained in:
Axel Wagner 2010-06-17 21:33:28 +02:00 committed by Michael Stapelberg
parent 09967274d7
commit da595ee9f7

View File

@ -7,7 +7,13 @@ void print_time(const char *format) {
static char part[512];
/* Get date & time */
time_t current_time = time(NULL);
if (current_time == (time_t) -1) {
return;
}
struct tm *current_tm = localtime(&current_time);
if (current_tm == NULL) {
return;
}
(void)strftime(part, sizeof(part), format, current_tm);
printf("%s", part);
}