--- embedaddon/php/ext/fileinfo/libmagic/print.c 2012/05/29 12:34:39 1.1.1.2 +++ embedaddon/php/ext/fileinfo/libmagic/print.c 2013/07/22 01:31:50 1.1.1.3 @@ -33,9 +33,10 @@ #include "php.h" #include "file.h" +#include "cdf.h" #ifndef lint -FILE_RCSID("@(#)$File: print.c,v 1.71 2011/09/20 15:28:09 christos Exp $") +FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $") #endif /* lint */ #include @@ -47,6 +48,11 @@ FILE_RCSID("@(#)$File: print.c,v 1.71 2011/09/20 15:28 #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*/ @@ -58,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); @@ -67,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; @@ -96,7 +108,7 @@ file_fmttime(uint32_t v, int local) tm = gmtime(&t); if (tm == NULL) goto out; - pp = asctime(tm); + pp = asctime_r(tm, buf); } if (pp == NULL) @@ -104,5 +116,5 @@ file_fmttime(uint32_t v, int local) pp[strcspn(pp, "\n")] = '\0'; return pp; out: - return "*Invalid time*"; + return strcpy(buf, "*Invalid time*"); }