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.
|
.\" Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd November 7, 2008
|
.Dd February 16, 2011
|
||||||
.Dt STAT 1
|
.Dt STAT 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
.Op Fl t Ar timefmt
|
.Op Fl t Ar timefmt
|
||||||
.Op Ar
|
.Op Ar
|
||||||
.Nm readlink
|
.Nm readlink
|
||||||
.Op Fl fn
|
.Op Fl fnqsv
|
||||||
.Op Ar
|
.Op Ar
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
|
@ -165,11 +165,16 @@ epoch, etc.)
|
||||||
Display information in
|
Display information in
|
||||||
.Dq shell output ,
|
.Dq shell output ,
|
||||||
suitable for initializing variables.
|
suitable for initializing variables.
|
||||||
|
When run as
|
||||||
|
.Nm readlink ,
|
||||||
|
suppress error messages.
|
||||||
.It Fl t Ar timefmt
|
.It Fl t Ar timefmt
|
||||||
Display timestamps using the specified format.
|
Display timestamps using the specified format.
|
||||||
This format is
|
This format is
|
||||||
passed directly to
|
passed directly to
|
||||||
.Xr strftime 3 .
|
.Xr strftime 3 .
|
||||||
|
.It Fl v
|
||||||
|
Turn off quiet mode.
|
||||||
.It Fl x
|
.It Fl x
|
||||||
Display information in a more verbose way as known from some Linux
|
Display information in a more verbose way as known from some Linux
|
||||||
distributions.
|
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.
|
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if !defined(lint)
|
#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
|
#endif
|
||||||
|
|
||||||
#if ! HAVE_NBTOOL_CONFIG_H
|
#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 usage(const char *);
|
||||||
void output(const struct stat *, 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 */
|
int format1(const struct stat *, /* stat info */
|
||||||
const char *, /* the file name */
|
const char *, /* the file name */
|
||||||
const char *, int, /* the format string itself */
|
const char *, int, /* the format string itself */
|
||||||
char *, size_t, /* a place to put the output */
|
char *, size_t, /* a place to put the output */
|
||||||
int, int, int, int, /* the parsed format */
|
int, int, int, int, /* the parsed format */
|
||||||
int, int);
|
int, int, int);
|
||||||
|
|
||||||
const char *timefmt;
|
const char *timefmt;
|
||||||
int linkfail;
|
int linkfail;
|
||||||
|
@ -211,10 +211,12 @@ main(int argc, char *argv[])
|
||||||
statfmt = NULL;
|
statfmt = NULL;
|
||||||
timefmt = NULL;
|
timefmt = NULL;
|
||||||
|
|
||||||
|
setprogname(argv[0]);
|
||||||
|
|
||||||
if (strcmp(getprogname(), "readlink") == 0) {
|
if (strcmp(getprogname(), "readlink") == 0) {
|
||||||
am_readlink = 1;
|
am_readlink = 1;
|
||||||
options = "fn";
|
options = "fnqsv";
|
||||||
synopsis = "[-fn] [file ...]";
|
synopsis = "[-fnqsv] [file ...]";
|
||||||
statfmt = "%Y";
|
statfmt = "%Y";
|
||||||
fmtchar = 'f';
|
fmtchar = 'f';
|
||||||
quiet = 1;
|
quiet = 1;
|
||||||
|
@ -247,6 +249,11 @@ main(int argc, char *argv[])
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'r':
|
case 'r':
|
||||||
case 's':
|
case 's':
|
||||||
|
if (am_readlink) {
|
||||||
|
quiet = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*FALLTHROUGH*/
|
||||||
case 'x':
|
case 'x':
|
||||||
if (fmtchar != 0)
|
if (fmtchar != 0)
|
||||||
errx(1, "can't use format '%c' with '%c'",
|
errx(1, "can't use format '%c' with '%c'",
|
||||||
|
@ -256,6 +263,9 @@ main(int argc, char *argv[])
|
||||||
case 't':
|
case 't':
|
||||||
timefmt = optarg;
|
timefmt = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
quiet = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(synopsis);
|
usage(synopsis);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +339,7 @@ main(int argc, char *argv[])
|
||||||
usestat ? "stat" : "lstat");
|
usestat ? "stat" : "lstat");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
output(&st, argv[0], statfmt, fn, nonl);
|
output(&st, argv[0], statfmt, fn, nonl, quiet);
|
||||||
|
|
||||||
argv++;
|
argv++;
|
||||||
argc--;
|
argc--;
|
||||||
|
@ -352,7 +362,7 @@ usage(const char *synopsis)
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
output(const struct stat *st, const char *file,
|
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;
|
int flags, size, prec, ofmt, hilo, what;
|
||||||
char buf[PATH_MAX + 4 + 1];
|
char buf[PATH_MAX + 4 + 1];
|
||||||
|
@ -523,7 +533,7 @@ output(const struct stat *st, const char *file,
|
||||||
file,
|
file,
|
||||||
subfmt, statfmt - subfmt,
|
subfmt, statfmt - subfmt,
|
||||||
buf, sizeof(buf),
|
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++)
|
for (i = 0; i < t && i < (int)(sizeof(buf) - 1); i++)
|
||||||
addchar(stdout, buf[i], &nl);
|
addchar(stdout, buf[i], &nl);
|
||||||
|
@ -549,7 +559,7 @@ format1(const struct stat *st,
|
||||||
const char *fmt, int flen,
|
const char *fmt, int flen,
|
||||||
char *buf, size_t blen,
|
char *buf, size_t blen,
|
||||||
int flags, int size, int prec, int ofmt,
|
int flags, int size, int prec, int ofmt,
|
||||||
int hilo, int what)
|
int hilo, int what, int quiet)
|
||||||
{
|
{
|
||||||
u_int64_t data;
|
u_int64_t data;
|
||||||
char *stmp, lfmt[24], tmp[20];
|
char *stmp, lfmt[24], tmp[20];
|
||||||
|
@ -797,6 +807,8 @@ format1(const struct stat *st,
|
||||||
} else {
|
} else {
|
||||||
snprintf(path, sizeof(path), " -> ");
|
snprintf(path, sizeof(path), " -> ");
|
||||||
if (realpath(file, path + 4) == NULL) {
|
if (realpath(file, path + 4) == NULL) {
|
||||||
|
if (!quiet)
|
||||||
|
warn("realpath `%s'", file);
|
||||||
linkfail = 1;
|
linkfail = 1;
|
||||||
l = 0;
|
l = 0;
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
|
@ -815,6 +827,8 @@ format1(const struct stat *st,
|
||||||
snprintf(path, sizeof(path), " -> ");
|
snprintf(path, sizeof(path), " -> ");
|
||||||
l = readlink(file, path + 4, sizeof(path) - 4 - 1);
|
l = readlink(file, path + 4, sizeof(path) - 4 - 1);
|
||||||
if (l == -1) {
|
if (l == -1) {
|
||||||
|
if (!quiet)
|
||||||
|
warn("readlink `%s'", file);
|
||||||
linkfail = 1;
|
linkfail = 1;
|
||||||
l = 0;
|
l = 0;
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
|
@ -933,13 +947,13 @@ format1(const struct stat *st,
|
||||||
fmt, flen,
|
fmt, flen,
|
||||||
majdev, sizeof(majdev),
|
majdev, sizeof(majdev),
|
||||||
flags, size, prec,
|
flags, size, prec,
|
||||||
ofmt, HIGH_PIECE, SHOW_st_rdev);
|
ofmt, HIGH_PIECE, SHOW_st_rdev, quiet);
|
||||||
l2 = format1(st,
|
l2 = format1(st,
|
||||||
file,
|
file,
|
||||||
fmt, flen,
|
fmt, flen,
|
||||||
mindev, sizeof(mindev),
|
mindev, sizeof(mindev),
|
||||||
flags, size, prec,
|
flags, size, prec,
|
||||||
ofmt, LOW_PIECE, SHOW_st_rdev);
|
ofmt, LOW_PIECE, SHOW_st_rdev, quiet);
|
||||||
return (snprintf(buf, blen, "%.*s,%.*s",
|
return (snprintf(buf, blen, "%.*s,%.*s",
|
||||||
l1, majdev, l2, mindev));
|
l1, majdev, l2, mindev));
|
||||||
}
|
}
|
||||||
|
@ -949,7 +963,7 @@ format1(const struct stat *st,
|
||||||
fmt, flen,
|
fmt, flen,
|
||||||
buf, blen,
|
buf, blen,
|
||||||
flags, size, prec,
|
flags, size, prec,
|
||||||
ofmt, 0, SHOW_st_size));
|
ofmt, 0, SHOW_st_size, quiet));
|
||||||
}
|
}
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue