Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/stat Add verbose mode for readlink.



details:   https://anonhg.NetBSD.org/src/rev/fffbb2c08fa5
branches:  trunk
changeset: 762164:fffbb2c08fa5
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 16 23:08:29 2011 +0000

description:
Add verbose mode for readlink.

diffstat:

 usr.bin/stat/stat.1 |  11 ++++++++---
 usr.bin/stat/stat.c |  40 +++++++++++++++++++++++++++-------------
 2 files changed, 35 insertions(+), 16 deletions(-)

diffs (194 lines):

diff -r bd5a19986fa4 -r fffbb2c08fa5 usr.bin/stat/stat.1
--- a/usr.bin/stat/stat.1       Wed Feb 16 22:35:41 2011 +0000
+++ b/usr.bin/stat/stat.1       Wed Feb 16 23:08:29 2011 +0000
@@ -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.
diff -r bd5a19986fa4 -r fffbb2c08fa5 usr.bin/stat/stat.c
--- a/usr.bin/stat/stat.c       Wed Feb 16 22:35:41 2011 +0000
+++ b/usr.bin/stat/stat.c       Wed Feb 16 23:08:29 2011 +0000
@@ -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:



Home | Main Index | Thread Index | Old Index