summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-10-13 17:59:43 +0000
committerMatt Kraai <kraai@debian.org>2000-10-13 17:59:43 +0000
commit33fdae54d129212c65590ecd6e2f77a78c59e46c (patch)
tree4321d2d22dbd21ec31083bc8a9e897017f469335
parente7e1e2dcadc48d9de9b3ad64e589c8d419b58aa9 (diff)
Exit with failure status if we are unable to list any files or
directories. Patch thanks to Kent Robotti <robotti@metconnect.com>.
-rw-r--r--coreutils/ls.c9
-rw-r--r--ls.c9
2 files changed, 16 insertions, 2 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index a35070f20..28b2f954d 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -173,6 +173,8 @@ static unsigned short tabstops = 8;
#define column_width COLUMN_WIDTH
#endif
+static int status = EXIT_SUCCESS;
+
static void newline(void)
{
if (column > 0) {
@@ -459,6 +461,7 @@ struct dnode **list_dir(char *path)
dir = opendir(path);
if (dir == NULL) {
errorMsg("%s: %s\n", path, strerror(errno));
+ status = EXIT_FAILURE;
return(NULL); /* could not open the dir */
}
while ((entry = readdir(dir)) != NULL) {
@@ -477,6 +480,7 @@ struct dnode **list_dir(char *path)
if (follow_links == TRUE) {
if (stat(cur->fullname, &cur->dstat)) {
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -485,6 +489,7 @@ struct dnode **list_dir(char *path)
#endif
if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -791,6 +796,7 @@ extern int ls_main(int argc, char **argv)
if (follow_links == TRUE) {
if (stat(av[oi], &cur->dstat)) {
errorMsg("%s: %s\n", av[oi], strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -799,6 +805,7 @@ extern int ls_main(int argc, char **argv)
#endif
if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
errorMsg("%s: %s\n", av[oi], strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -842,7 +849,7 @@ extern int ls_main(int argc, char **argv)
}
}
- return(0);
+ return(status);
print_usage_message:
usage(ls_usage);
diff --git a/ls.c b/ls.c
index a35070f20..28b2f954d 100644
--- a/ls.c
+++ b/ls.c
@@ -173,6 +173,8 @@ static unsigned short tabstops = 8;
#define column_width COLUMN_WIDTH
#endif
+static int status = EXIT_SUCCESS;
+
static void newline(void)
{
if (column > 0) {
@@ -459,6 +461,7 @@ struct dnode **list_dir(char *path)
dir = opendir(path);
if (dir == NULL) {
errorMsg("%s: %s\n", path, strerror(errno));
+ status = EXIT_FAILURE;
return(NULL); /* could not open the dir */
}
while ((entry = readdir(dir)) != NULL) {
@@ -477,6 +480,7 @@ struct dnode **list_dir(char *path)
if (follow_links == TRUE) {
if (stat(cur->fullname, &cur->dstat)) {
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -485,6 +489,7 @@ struct dnode **list_dir(char *path)
#endif
if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
errorMsg("%s: %s\n", cur->fullname, strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -791,6 +796,7 @@ extern int ls_main(int argc, char **argv)
if (follow_links == TRUE) {
if (stat(av[oi], &cur->dstat)) {
errorMsg("%s: %s\n", av[oi], strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -799,6 +805,7 @@ extern int ls_main(int argc, char **argv)
#endif
if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
errorMsg("%s: %s\n", av[oi], strerror(errno));
+ status = EXIT_FAILURE;
free(cur->fullname);
free(cur);
continue;
@@ -842,7 +849,7 @@ extern int ls_main(int argc, char **argv)
}
}
- return(0);
+ return(status);
print_usage_message:
usage(ls_usage);