aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/stat
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2010-12-05 21:11:45 +0000
committerDoug Barton <dougb@FreeBSD.org>2010-12-05 21:11:45 +0000
commitb9f9338ea87a2ad5e901e6bc61fdbef06a25b004 (patch)
treed3bbabd6cca86f8e0082b773290dc65a0067329d /usr.bin/stat
parent578800b575fc83f2012668f24bee8ccd0df10c4c (diff)
Notes
Diffstat (limited to 'usr.bin/stat')
-rw-r--r--usr.bin/stat/stat.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c
index a56927edeeac1..2b1eebcd032b5 100644
--- a/usr.bin/stat/stat.c
+++ b/usr.bin/stat/stat.c
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if 0
#ifndef lint
-__RCSID("$NetBSD: stat.c,v 1.22 2005/04/22 03:36:48 atatat Exp $");
+__RCSID("$NetBSD: stat.c,v 1.27 2008/05/16 17:58:33 atatat Exp $");
#endif
#endif
@@ -153,6 +153,7 @@ __FBSDID("$FreeBSD$");
#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'
@@ -218,8 +219,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;
@@ -243,6 +244,10 @@ main(int argc, char *argv[])
quiet = 1;
break;
case 'f':
+ if (am_readlink) {
+ statfmt = "%R";
+ break;
+ }
statfmt = optarg;
/* FALLTHROUGH */
case 'l':
@@ -518,6 +523,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);
@@ -776,6 +782,26 @@ format1(const struct stat *st,
ofmt = FMTF_UNSIGNED;
break;
#endif /* HAVE_STRUCT_STAT_ST_GEN */
+ case SHOW_realpath:
+ small = 0;
+ data = 0;
+ if (file == NULL) {
+ (void)strncpy(path, "(stdin)", sizeof(path));
+ sdata = path;
+ } else {
+ snprintf(path, sizeof(path), " -> ");
+ if (realpath(file, path + 4) == NULL) {
+ linkfail = 1;
+ l = 0;
+ path[0] = '\0';
+ }
+ sdata = path + (ofmt == FMTF_STRING ? 0 : 4);
+ }
+
+ formats = FMTF_STRING;
+ if (ofmt == 0)
+ ofmt = FMTF_STRING;
+ break;
case SHOW_symlink:
small = 0;
data = 0;