From owner-svn-src-all@FreeBSD.ORG Sun Dec 5 21:53:13 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F12F1065672; Sun, 5 Dec 2010 21:53:13 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 13CF78FC13; Sun, 5 Dec 2010 21:53:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oB5LrC2A009481; Sun, 5 Dec 2010 21:53:12 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oB5LrCEt009479; Sun, 5 Dec 2010 21:53:12 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201012052153.oB5LrCEt009479@svn.freebsd.org> From: Doug Barton Date: Sun, 5 Dec 2010 21:53:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216207 - head/usr.bin/stat X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Dec 2010 21:53:13 -0000 Author: dougb Date: Sun Dec 5 21:53:12 2010 New Revision: 216207 URL: http://svn.freebsd.org/changeset/base/216207 Log: 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) Modified: head/usr.bin/stat/stat.c Modified: head/usr.bin/stat/stat.c ============================================================================== --- head/usr.bin/stat/stat.c Sun Dec 5 21:33:05 2010 (r216206) +++ head/usr.bin/stat/stat.c Sun Dec 5 21:53:12 2010 (r216207) @@ -30,7 +30,7 @@ #include #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);