Module Name:    src
Committed By:   erh
Date:           Sun Dec  2 21:13:07 UTC 2012

Modified Files:
        src/usr.bin/stat: stat.1 stat.c

Log Message:
Honor the -t option to set the time format when running stat -s.
Document the format used by -s on the man page.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/stat/stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/stat/stat.1
diff -u src/usr.bin/stat/stat.1:1.34 src/usr.bin/stat/stat.1:1.35
--- src/usr.bin/stat/stat.1:1.34	Thu Sep 22 20:23:55 2011
+++ src/usr.bin/stat/stat.1	Sun Dec  2 21:13:07 2012
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.34 2011/09/22 20:23:55 apb Exp $
+.\"	$NetBSD: stat.1,v 1.35 2012/12/02 21:13:07 erh Exp $
 .\"
 .\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -168,6 +168,17 @@ suitable for initializing variables.
 When run as
 .Nm readlink ,
 suppress error messages.
+This is equivalent to specifying 
+.Bd -literal 
+FMT="st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l st_uid=%u st_gid=%g"
+FMT="$FMT st_rdev=%r st_size=%z st_atime=%Sa st_mtime=%Sm st_ctime=%Sc"
+FMT="$FMT st_birthtime=%SB st_blksize=%k st_blocks=%b st_flags=%f"
+stat -t %s -f "$FMT" .
+.Ed
+Note that if you use a timeformat that contains embedded whitespace or shell 
+meta-characters you will need to include appropriate quoting so the
+.Fl s
+output remains valid.
 .It Fl t Ar timefmt
 Display timestamps using the specified format.
 This format is

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.36 src/usr.bin/stat/stat.c:1.37
--- src/usr.bin/stat/stat.c:1.36	Thu Sep 22 20:23:56 2011
+++ src/usr.bin/stat/stat.c	Sun Dec  2 21:13:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $ */
+/*	$NetBSD: stat.c,v 1.37 2012/12/02 21:13:07 erh Exp $ */
 
 /*
  * Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.36 2011/09/22 20:23:56 apb Exp $");
+__RCSID("$NetBSD: stat.c,v 1.37 2012/12/02 21:13:07 erh Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -76,7 +76,7 @@ __RCSID("$NetBSD: stat.c,v 1.36 2011/09/
 #if HAVE_STRUCT_STAT_ST_BIRTHTIME
 #define DEF_B "\"%SB\" "
 #define RAW_B "%B "
-#define SHELL_B "st_birthtime=%B "
+#define SHELL_B "st_birthtime=%SB "
 #else /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
 #define DEF_B
 #define RAW_B
@@ -99,7 +99,7 @@ __RCSID("$NetBSD: stat.c,v 1.36 2011/09/
 #define SHELL_FORMAT \
 	"st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l " \
 	"st_uid=%u st_gid=%g st_rdev=%r st_size=%z " \
-	"st_atime=%a st_mtime=%m st_ctime=%c " SHELL_B \
+	"st_atime=%Sa st_mtime=%Sm st_ctime=%Sc " SHELL_B \
 	"st_blksize=%k st_blocks=%b" SHELL_F
 #define LINUX_FORMAT \
 	"  File: \"%N\"%n" \
@@ -299,6 +299,8 @@ main(int argc, char *argv[])
 		break;
 	case 's':
 		statfmt = SHELL_FORMAT;
+		if (timefmt == NULL)
+			timefmt = "%s";
 		break;
 	case 'x':
 		statfmt = LINUX_FORMAT;

Reply via email to