summaryrefslogtreecommitdiff
path: root/usr.bin/stat
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2010-12-05 21:53:12 +0000
committerDoug Barton <dougb@FreeBSD.org>2010-12-05 21:53:12 +0000
commitda78facc72299595ff985f0fe9137bb560fd3c58 (patch)
tree050a3f467dd409341bbd9ea87b9dbf7d18883370 /usr.bin/stat
parentd7233fd61504a4d2e3740d8fb4c121c78a278ecf (diff)
downloadsrc-test-da78facc72299595ff985f0fe9137bb560fd3c58.tar.gz
src-test-da78facc72299595ff985f0fe9137bb560fd3c58.zip
Bring in the following changes from NetBSD. See the discussion at:
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=44128 1.29 "Don't printf time_t with %d; fixes PR 44128 from yamt. With this change it successfully prints mtimes after 2038." 1.30 "Improve previous with comments." Obtained from: dholland@NetBSD.org (both)
Notes
Notes: svn path=/head/; revision=216207
Diffstat (limited to 'usr.bin/stat')
-rw-r--r--usr.bin/stat/stat.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c
index e3e8c33ba2411..950c76abb95cb 100644
--- a/usr.bin/stat/stat.c
+++ b/usr.bin/stat/stat.c
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if 0
#ifndef lint
-__RCSID("$NetBSD: stat.c,v 1.28 2009/04/13 23:02:36 lukem Exp $");
+__RCSID("$NetBSD: stat.c,v 1.30 2010/11/25 04:33:30 dholland Exp $");
#endif
#endif
@@ -728,7 +728,6 @@ format1(const struct stat *st,
ts = *tsp; /* copy so we can muck with it */
small = (sizeof(ts.tv_sec) == 4);
data = ts.tv_sec;
- small = 1;
tm = localtime(&ts.tv_sec);
(void)strftime(path, sizeof(path), timefmt, tm);
sdata = path;
@@ -951,8 +950,9 @@ format1(const struct stat *st,
(void)snprintf(tmp, sizeof(tmp), "%d", size);
(void)strcat(lfmt, tmp);
}
- (void)strcat(lfmt, "d");
- return (snprintf(buf, blen, lfmt, ts.tv_sec));
+ (void)strcat(lfmt, "lld");
+ return (snprintf(buf, blen, lfmt,
+ (long long)ts.tv_sec));
}
/*
@@ -975,7 +975,8 @@ format1(const struct stat *st,
(void)snprintf(tmp, sizeof(tmp), "%d", size);
(void)strcat(lfmt, tmp);
}
- (void)strcat(lfmt, "d");
+ /* Seconds: time_t cast to long long. */
+ (void)strcat(lfmt, "lld");
/*
* The stuff after the decimal point always needs zero
@@ -986,8 +987,10 @@ format1(const struct stat *st,
/*
* We can "print" at most nine digits of precision. The
* rest we will pad on at the end.
+ *
+ * Nanoseconds: long.
*/
- (void)snprintf(tmp, sizeof(tmp), "%dd", prec > 9 ? 9 : prec);
+ (void)snprintf(tmp, sizeof(tmp), "%dld", prec > 9 ? 9 : prec);
(void)strcat(lfmt, tmp);
/*
@@ -1001,7 +1004,7 @@ format1(const struct stat *st,
* Use the format, and then tack on any zeroes that
* might be required to make up the requested precision.
*/
- l = snprintf(buf, blen, lfmt, ts.tv_sec, ts.tv_nsec);
+ l = snprintf(buf, blen, lfmt, (long long)ts.tv_sec, ts.tv_nsec);
for (; prec > 9 && l < (int)blen; prec--, l++)
(void)strcat(buf, "0");
return (l);