--- embedaddon/php/ext/fileinfo/libmagic/print.c 2012/02/21 23:47:56 1.1 +++ embedaddon/php/ext/fileinfo/libmagic/print.c 2013/07/22 01:31:50 1.1.1.3 @@ -29,15 +29,17 @@ * print.c - debugging printout routines */ +#define _GNU_SOURCE #include "php.h" -#include "main/snprintf.h" #include "file.h" +#include "cdf.h" #ifndef lint -FILE_RCSID("@(#)$File: print.c,v 1.66 2009/02/03 20:27:51 christos Exp $") +FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $") #endif /* lint */ +#include #include #include #include @@ -46,6 +48,11 @@ FILE_RCSID("@(#)$File: print.c,v 1.66 2009/02/03 20:27 #endif #include +#ifdef PHP_WIN32 +# define asctime_r php_asctime_r +# define ctime_r php_ctime_r +#endif + #define SZOF(a) (sizeof(a) / sizeof(a[0])) /*VARARGS*/ @@ -57,7 +64,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...) TSRMLS_FETCH(); va_start(va, f); - vasprintf(&expanded_format, f, va); + if (vasprintf(&expanded_format, f, va)); /* silence */ va_end(va); php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format); @@ -66,14 +73,20 @@ file_magwarn(struct magic_set *ms, const char *f, ...) } protected const char * -file_fmttime(uint32_t v, int local) +file_fmttime(uint64_t v, int flags, char *buf) { char *pp; time_t t = (time_t)v; struct tm *tm; - if (local) { - pp = ctime(&t); + if (flags & FILE_T_WINDOWS) { + struct timeval ts; + cdf_timestamp_to_timespec(&ts, t); + t = ts.tv_sec; + } + + if (flags & FILE_T_LOCAL) { + pp = ctime_r(&t, buf); } else { #ifndef HAVE_DAYLIGHT private int daylight = 0; @@ -85,7 +98,7 @@ file_fmttime(uint32_t v, int local) (void)time(&now); tm1 = localtime(&now); if (tm1 == NULL) - return "*Invalid time*"; + goto out; daylight = tm1->tm_isdst; } #endif /* HAVE_TM_ISDST */ @@ -94,10 +107,14 @@ file_fmttime(uint32_t v, int local) t += 3600; tm = gmtime(&t); if (tm == NULL) - return "*Invalid time*"; - pp = asctime(tm); + goto out; + pp = asctime_r(tm, buf); } + if (pp == NULL) + goto out; pp[strcspn(pp, "\n")] = '\0'; return pp; +out: + return strcpy(buf, "*Invalid time*"); }