PR/34662: martijnb at atlas dot ipv6 dot stack dot nl: readlink doesn't
grok -f, and there's no alternative (+fix) Patch applied with minor tweak (%y -> %R, as it was already taken) plus some nits from myself. Thanks!
This commit is contained in:
parent
e35f123530
commit
2a7d09e7cd
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: stat.1,v 1.18 2005/06/26 10:16:46 wiz Exp $
|
||||
.\" $NetBSD: stat.1,v 1.19 2006/10/07 10:41:50 elad Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2002-2005 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
|
@ -34,7 +34,7 @@
|
|||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd June 23, 2005
|
||||
.Dd October 7, 2006
|
||||
.Dt STAT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -54,7 +54,7 @@
|
|||
.Op Fl t Ar timefmt
|
||||
.Op Ar
|
||||
.Nm readlink
|
||||
.Op Fl n
|
||||
.Op Fl fn
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
|
@ -71,9 +71,20 @@ displays information about the file descriptor for standard input.
|
|||
When invoked as
|
||||
.Nm readlink ,
|
||||
only the target of the symbolic link is printed.
|
||||
If the given argument is not a symbolic link,
|
||||
If the given argument is not a symbolic link and the
|
||||
.Fl f
|
||||
option is not specified,
|
||||
.Nm readlink
|
||||
will print nothing and exit with an error.
|
||||
If the
|
||||
.Fl f
|
||||
option is specified, the output is canonicalized by following every symlink
|
||||
in every component of the given path recursively.
|
||||
.Nm readlink
|
||||
will resolve both absolute and relative paths, and return the absolute pathname
|
||||
corresponding to
|
||||
.Ar file .
|
||||
In this case, the argument does not need to be a symbolic link.
|
||||
.Pp
|
||||
The information displayed is obtained by calling
|
||||
.Xr lstat 2
|
||||
|
@ -379,11 +390,13 @@ User defined flags for
|
|||
Inode generation number.
|
||||
.El
|
||||
.Pp
|
||||
The following four field specifiers are not drawn directly from the
|
||||
The following five field specifiers are not drawn directly from the
|
||||
data in struct stat, but are:
|
||||
.Bl -tag -width Ds
|
||||
.It Cm N
|
||||
The name of the file.
|
||||
.It Cm R
|
||||
The absolute pathname corresponding to the file.
|
||||
.It Cm T
|
||||
The file type, either as in
|
||||
.Ic ls -F
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: stat.c,v 1.23 2005/06/23 03:13:24 atatat Exp $ */
|
||||
/* $NetBSD: stat.c,v 1.24 2006/10/07 10:41:50 elad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -42,7 +42,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint)
|
||||
__RCSID("$NetBSD: stat.c,v 1.23 2005/06/23 03:13:24 atatat Exp $");
|
||||
__RCSID("$NetBSD: stat.c,v 1.24 2006/10/07 10:41:50 elad Exp $");
|
||||
#endif
|
||||
|
||||
#if ! HAVE_NBTOOL_CONFIG_H
|
||||
|
@ -159,6 +159,7 @@ __RCSID("$NetBSD: stat.c,v 1.23 2005/06/23 03:13:24 atatat Exp $");
|
|||
#define MIDDLE_PIECE 'M'
|
||||
#define LOW_PIECE 'L'
|
||||
|
||||
#define SHOW_realpath 'R'
|
||||
#define SHOW_st_dev 'd'
|
||||
#define SHOW_st_ino 'i'
|
||||
#define SHOW_st_mode 'p'
|
||||
|
@ -219,8 +220,8 @@ main(int argc, char *argv[])
|
|||
|
||||
if (strcmp(getprogname(), "readlink") == 0) {
|
||||
am_readlink = 1;
|
||||
options = "n";
|
||||
synopsis = "[-n] [file ...]";
|
||||
options = "fn";
|
||||
synopsis = "[-fn] [file ...]";
|
||||
statfmt = "%Y";
|
||||
fmtchar = 'f';
|
||||
quiet = 1;
|
||||
|
@ -244,6 +245,10 @@ main(int argc, char *argv[])
|
|||
quiet = 1;
|
||||
break;
|
||||
case 'f':
|
||||
if (am_readlink) {
|
||||
statfmt = "%R";
|
||||
break;
|
||||
}
|
||||
statfmt = optarg;
|
||||
/* FALLTHROUGH */
|
||||
case 'l':
|
||||
|
@ -494,6 +499,7 @@ output(const struct stat *st, const char *file,
|
|||
}
|
||||
|
||||
switch (*statfmt) {
|
||||
fmtcase(what, SHOW_realpath);
|
||||
fmtcase(what, SHOW_st_dev);
|
||||
fmtcase(what, SHOW_st_ino);
|
||||
fmtcase(what, SHOW_st_mode);
|
||||
|
@ -784,6 +790,21 @@ format1(const struct stat *st,
|
|||
ofmt = FMTF_UNSIGNED;
|
||||
break;
|
||||
#endif /* HAVE_STRUCT_STAT_ST_GEN */
|
||||
case SHOW_realpath:
|
||||
small = 0;
|
||||
data = 0;
|
||||
snprintf(path, sizeof(path), " -> ");
|
||||
if (realpath(file, path + 4) == NULL) {
|
||||
linkfail = 1;
|
||||
l = 0;
|
||||
path[0] = '\0';
|
||||
}
|
||||
sdata = path + (ofmt == FMT_STRING ? 0: 4);
|
||||
|
||||
formats = FMTF_STRING;
|
||||
if (ofmt == 0)
|
||||
ofmt = FMTF_STRING;
|
||||
break;
|
||||
case SHOW_symlink:
|
||||
small = 0;
|
||||
data = 0;
|
||||
|
|
Loading…
Reference in New Issue