Module Name:    src
Committed By:   christos
Date:           Wed Feb 16 23:08:29 UTC 2011

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

Log Message:
Add verbose mode for readlink.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/stat/stat.1
cvs rdiff -u -r1.33 -r1.34 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.28 src/usr.bin/stat/stat.1:1.29
--- src/usr.bin/stat/stat.1:1.28	Mon Apr  5 17:25:01 2010
+++ src/usr.bin/stat/stat.1	Wed Feb 16 18:08:29 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: stat.1,v 1.28 2010/04/05 21:25:01 joerg Exp $
+.\"	$NetBSD: stat.1,v 1.29 2011/02/16 23:08:29 christos Exp $
 .\"
 .\" Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 7, 2008
+.Dd February 16, 2011
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -47,7 +47,7 @@
 .Op Fl t Ar timefmt
 .Op Ar
 .Nm readlink
-.Op Fl fn
+.Op Fl fnqsv
 .Op Ar
 .Sh DESCRIPTION
 The
@@ -165,11 +165,16 @@
 Display information in
 .Dq shell output ,
 suitable for initializing variables.
+When run as
+.Nm readlink ,
+suppress error messages.
 .It Fl t Ar timefmt
 Display timestamps using the specified format.
 This format is
 passed directly to
 .Xr strftime 3 .
+.It Fl v
+Turn off quiet mode.
 .It Fl x
 Display information in a more verbose way as known from some Linux
 distributions.

Index: src/usr.bin/stat/stat.c
diff -u src/usr.bin/stat/stat.c:1.33 src/usr.bin/stat/stat.c:1.34
--- src/usr.bin/stat/stat.c:1.33	Sat Jan 15 17:54:10 2011
+++ src/usr.bin/stat/stat.c	Wed Feb 16 18:08:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $ */
+/*	$NetBSD: stat.c,v 1.34 2011/02/16 23:08:29 christos Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $");
+__RCSID("$NetBSD: stat.c,v 1.34 2011/02/16 23:08:29 christos Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -176,13 +176,13 @@
 
 void	usage(const char *);
 void	output(const struct stat *, const char *,
-	    const char *, int, int);
+	    const char *, int, int, int);
 int	format1(const struct stat *,	/* stat info */
 	    const char *,		/* the file name */
 	    const char *, int,		/* the format string itself */
 	    char *, size_t,		/* a place to put the output */
 	    int, int, int, int,		/* the parsed format */
-	    int, int);
+	    int, int, int);
 
 const char *timefmt;
 int linkfail;
@@ -211,10 +211,12 @@
 	statfmt = NULL;
 	timefmt = NULL;
 
+	setprogname(argv[0]);
+
 	if (strcmp(getprogname(), "readlink") == 0) {
 		am_readlink = 1;
-		options = "fn";
-		synopsis = "[-fn] [file ...]";
+		options = "fnqsv";
+		synopsis = "[-fnqsv] [file ...]";
 		statfmt = "%Y";
 		fmtchar = 'f';
 		quiet = 1;
@@ -247,6 +249,11 @@
 		case 'l':
 		case 'r':
 		case 's':
+			if (am_readlink) {
+				quiet = 1;
+				break;
+			}
+			/*FALLTHROUGH*/
 		case 'x':
 			if (fmtchar != 0)
 				errx(1, "can't use format '%c' with '%c'",
@@ -256,6 +263,9 @@
 		case 't':
 			timefmt = optarg;
 			break;
+		case 'v':
+			quiet = 0;
+			break;
 		default:
 			usage(synopsis);
 		}
@@ -329,7 +339,7 @@
 				    usestat ? "stat" : "lstat");
 		}
 		else
-			output(&st, argv[0], statfmt, fn, nonl);
+			output(&st, argv[0], statfmt, fn, nonl, quiet);
 
 		argv++;
 		argc--;
@@ -352,7 +362,7 @@
  */
 void
 output(const struct stat *st, const char *file,
-    const char *statfmt, int fn, int nonl)
+    const char *statfmt, int fn, int nonl, int quiet)
 {
 	int flags, size, prec, ofmt, hilo, what;
 	char buf[PATH_MAX + 4 + 1];
@@ -523,7 +533,7 @@
 		     file,
 		     subfmt, statfmt - subfmt,
 		     buf, sizeof(buf),
-		     flags, size, prec, ofmt, hilo, what);
+		     flags, size, prec, ofmt, hilo, what, quiet);
 
 		for (i = 0; i < t && i < (int)(sizeof(buf) - 1); i++)
 			addchar(stdout, buf[i], &nl);
@@ -549,7 +559,7 @@
     const char *fmt, int flen,
     char *buf, size_t blen,
     int flags, int size, int prec, int ofmt,
-    int hilo, int what)
+    int hilo, int what, int quiet)
 {
 	u_int64_t data;
 	char *stmp, lfmt[24], tmp[20];
@@ -797,6 +807,8 @@
 		} else {
 			snprintf(path, sizeof(path), " -> ");
 			if (realpath(file, path + 4) == NULL) {
+				if (!quiet)
+					warn("realpath `%s'", file);
 				linkfail = 1;
 				l = 0;
 				path[0] = '\0';
@@ -815,6 +827,8 @@
 			snprintf(path, sizeof(path), " -> ");
 			l = readlink(file, path + 4, sizeof(path) - 4 - 1);
 			if (l == -1) {
+				if (!quiet)
+					warn("readlink `%s'", file);
 				linkfail = 1;
 				l = 0;
 				path[0] = '\0';
@@ -933,13 +947,13 @@
 			    fmt, flen,
 			    majdev, sizeof(majdev),
 			    flags, size, prec,
-			    ofmt, HIGH_PIECE, SHOW_st_rdev);
+			    ofmt, HIGH_PIECE, SHOW_st_rdev, quiet);
 			l2 = format1(st,
 			    file,
 			    fmt, flen,
 			    mindev, sizeof(mindev),
 			    flags, size, prec,
-			    ofmt, LOW_PIECE, SHOW_st_rdev);
+			    ofmt, LOW_PIECE, SHOW_st_rdev, quiet);
 			return (snprintf(buf, blen, "%.*s,%.*s",
 			    l1, majdev, l2, mindev));
 		}
@@ -949,7 +963,7 @@
 			    fmt, flen,
 			    buf, blen,
 			    flags, size, prec,
-			    ofmt, 0, SHOW_st_size));
+			    ofmt, 0, SHOW_st_size, quiet));
 		}
 		/*NOTREACHED*/
 	default:

Reply via email to