version 1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2013/10/14 07:56:35
|
Line 33
|
Line 33
|
char *get_timestr(time_t, int); |
char *get_timestr(time_t, int); |
|
|
/* |
/* |
* Return an ascii string with the current date + time | * Return a static buffer with the current date + time. |
* Uses strftime() if available, else falls back to ctime(). |
* Uses strftime() if available, else falls back to ctime(). |
*/ |
*/ |
char * |
char * |
Line 45 get_timestr(time_t tstamp, int log_year)
|
Line 45 get_timestr(time_t tstamp, int log_year)
|
struct tm *timeptr; |
struct tm *timeptr; |
|
|
timeptr = localtime(&tstamp); |
timeptr = localtime(&tstamp); |
if (log_year) |
|
s = "%h %e %T %Y"; |
|
else |
|
s = "%h %e %T"; |
|
|
|
/* strftime() does not guarantee to NUL-terminate so we must check. */ |
/* strftime() does not guarantee to NUL-terminate so we must check. */ |
buf[sizeof(buf) - 1] = '\0'; |
buf[sizeof(buf) - 1] = '\0'; |
if (strftime(buf, sizeof(buf), s, timeptr) && buf[sizeof(buf) - 1] == '\0') | if (strftime(buf, sizeof(buf), log_year ? "%h %e %T %Y" : "%h %e %T", |
| timeptr) != 0 && buf[sizeof(buf) - 1] == '\0') |
return buf; |
return buf; |
|
|
#endif /* HAVE_STRFTIME */ |
#endif /* HAVE_STRFTIME */ |