summaryrefslogtreecommitdiff
path: root/contrib/file/src/print.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2015-06-10 19:22:41 +0000
committerXin LI <delphij@FreeBSD.org>2015-06-10 19:22:41 +0000
commit5f0216bd883edee71bf81051e3c20505e4820903 (patch)
treebf2d8b473f0726bcdeb36d064078c17b8e7d13cf /contrib/file/src/print.c
parentfcf4d36e2516863a28bdd3d6bd891d40e1251a84 (diff)
parent76c08169d47becb14ee96abce87cb4167fd159f9 (diff)
Notes
Diffstat (limited to 'contrib/file/src/print.c')
-rw-r--r--contrib/file/src/print.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/contrib/file/src/print.c b/contrib/file/src/print.c
index fa817986740d..07ae8f6d8262 100644
--- a/contrib/file/src/print.c
+++ b/contrib/file/src/print.c
@@ -32,7 +32,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.79 2015/01/09 19:28:32 christos Exp $")
#endif /* lint */
#include <string.h>
@@ -164,6 +164,7 @@ file_mdump(struct magic *m)
case FILE_MELDATE:
(void)fprintf(stderr, "%s,",
file_fmttime(m->value.l, 0, tbuf));
+ break;
case FILE_QDATE:
case FILE_LEQDATE:
case FILE_BEQDATE:
@@ -231,40 +232,27 @@ protected const char *
file_fmttime(uint64_t v, int flags, char *buf)
{
char *pp;
- time_t t = (time_t)v;
- struct tm *tm;
+ time_t t;
+ struct tm *tm, tmz;
if (flags & FILE_T_WINDOWS) {
struct timespec ts;
- cdf_timestamp_to_timespec(&ts, t);
+ cdf_timestamp_to_timespec(&ts, v);
t = ts.tv_sec;
+ } else {
+ // XXX: perhaps detect and print something if overflow
+ // on 32 bit time_t?
+ t = (time_t)v;
}
if (flags & FILE_T_LOCAL) {
- pp = ctime_r(&t, buf);
+ tm = localtime_r(&t, &tmz);
} else {
-#ifndef HAVE_DAYLIGHT
- private int daylight = 0;
-#ifdef HAVE_TM_ISDST
- private time_t now = (time_t)0;
-
- if (now == (time_t)0) {
- struct tm *tm1;
- (void)time(&now);
- tm1 = localtime(&now);
- if (tm1 == NULL)
- goto out;
- daylight = tm1->tm_isdst;
- }
-#endif /* HAVE_TM_ISDST */
-#endif /* HAVE_DAYLIGHT */
- if (daylight)
- t += 3600;
- tm = gmtime(&t);
- if (tm == NULL)
- goto out;
- pp = asctime_r(tm, buf);
+ tm = gmtime_r(&t, &tmz);
}
+ if (tm == NULL)
+ goto out;
+ pp = asctime_r(tm, buf);
if (pp == NULL)
goto out;