Add verbose mode for readlink.
This commit is contained in:
parent
aa934b7969
commit
c544446f26
@ -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 @@ epoch, etc.)
|
||||
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.
|
||||
|
@ -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 @@ __RCSID("$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $");
|
||||
|
||||
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 @@ main(int argc, char *argv[])
|
||||
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 @@ main(int argc, char *argv[])
|
||||
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 @@ main(int argc, char *argv[])
|
||||
case 't':
|
||||
timefmt = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
quiet = 0;
|
||||
break;
|
||||
default:
|
||||
usage(synopsis);
|
||||
}
|
||||
@ -329,7 +339,7 @@ main(int argc, char *argv[])
|
||||
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 @@ usage(const char *synopsis)
|
||||
*/
|
||||
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 @@ output(const struct stat *st, const char *file,
|
||||
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 @@ format1(const struct stat *st,
|
||||
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 @@ format1(const struct stat *st,
|
||||
} 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 @@ format1(const struct stat *st,
|
||||
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 @@ format1(const struct stat *st,
|
||||
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 @@ format1(const struct stat *st,
|
||||
fmt, flen,
|
||||
buf, blen,
|
||||
flags, size, prec,
|
||||
ofmt, 0, SHOW_st_size));
|
||||
ofmt, 0, SHOW_st_size, quiet));
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user