aboutsummaryrefslogtreecommitdiff
path: root/bin/ls/ls.c
diff options
context:
space:
mode:
authorMaxime Henrion <mux@FreeBSD.org>2005-11-10 00:02:32 +0000
committerMaxime Henrion <mux@FreeBSD.org>2005-11-10 00:02:32 +0000
commit7b7d153b21013cd10e164bec1c3a035092866cc3 (patch)
treea23a583ac342cd95d705c81b8e81bbed9ad5303a /bin/ls/ls.c
parent6fe8148234b5aece1e3003d57afaa17e0db11df2 (diff)
downloadsrc-7b7d153b21013cd10e164bec1c3a035092866cc3.tar.gz
src-7b7d153b21013cd10e164bec1c3a035092866cc3.zip
Add a -I option to disable the automatic -A flag for the super-user.
PR: bin/86710 Submitted by: Marcus Alves Grando MFC after: 3 days
Notes
Notes: svn path=/head/; revision=152256
Diffstat (limited to 'bin/ls/ls.c')
-rw-r--r--bin/ls/ls.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index d8400eedad45..1e7586b333a5 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -110,6 +110,8 @@ int termwidth = 80; /* default terminal width */
static int f_kblocks; /* print size in kilobytes */
static int f_listdir; /* list actual directory, not contents */
static int f_listdot; /* list files beginning with . */
+static int f_nolistdot; /* don't list files beginning with . */
+static int f_forcelistdot; /* force list files beginning with . */
int f_longform; /* long listing format */
int f_nonprint; /* show unprintables as ? */
static int f_nosort; /* don't sort output */
@@ -175,13 +177,9 @@ main(int argc, char *argv[])
termwidth = atoi(p);
}
- /* Root is -A automatically. */
- if (!getuid())
- f_listdot = 1;
-
fts_options = FTS_PHYSICAL;
while ((ch = getopt(argc, argv,
- "1ABCFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
+ "1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
switch (ch) {
/*
* The -1, -C, -x and -l options all override each other so
@@ -243,10 +241,14 @@ main(int argc, char *argv[])
break;
case 'a':
fts_options |= FTS_SEEDOT;
- /* FALLTHROUGH */
+ f_forcelistdot = 1;
+ break;
case 'A':
f_listdot = 1;
break;
+ case 'I':
+ f_nolistdot = 1;
+ break;
/* The -d option turns off the -R option. */
case 'd':
f_listdir = 1;
@@ -326,6 +328,10 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
+ /* Root is -A automatically. */
+ if (!getuid() && !f_nolistdot)
+ f_listdot = 1;
+
/* Enabling of colours is conditional on the environment. */
if (getenv("CLICOLOR") &&
(isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
@@ -490,7 +496,8 @@ traverse(int argc, char *argv[], int options)
break;
case FTS_D:
if (p->fts_level != FTS_ROOTLEVEL &&
- p->fts_name[0] == '.' && !f_listdot)
+ p->fts_name[0] == '.' && ((!f_listdot ||
+ f_nolistdot) && !f_forcelistdot))
break;
/*
@@ -650,7 +657,8 @@ display(const FTSENT *p, FTSENT *list, int options)
}
} else {
/* Only display dot file if -a/-A set. */
- if (cur->fts_name[0] == '.' && !f_listdot) {
+ if (cur->fts_name[0] == '.' && ((!f_listdot ||
+ f_nolistdot) && !f_forcelistdot)) {
cur->fts_number = NO_PRINT;
continue;
}