summaryrefslogtreecommitdiff
path: root/ls.c
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 /ls.c
parente7e1e2dcadc48d9de9b3ad64e589c8d419b58aa9 (diff)
downloadbusybox-w32-33fdae54d129212c65590ecd6e2f77a78c59e46c.tar.gz
busybox-w32-33fdae54d129212c65590ecd6e2f77a78c59e46c.tar.bz2
busybox-w32-33fdae54d129212c65590ecd6e2f77a78c59e46c.zip
Exit with failure status if we are unable to list any files or
directories. Patch thanks to Kent Robotti <robotti@metconnect.com>.
Diffstat (limited to 'ls.c')
-rw-r--r--ls.c9
1 files changed, 8 insertions, 1 deletions
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;
173#define column_width COLUMN_WIDTH 173#define column_width COLUMN_WIDTH
174#endif 174#endif
175 175
176static int status = EXIT_SUCCESS;
177
176static void newline(void) 178static void newline(void)
177{ 179{
178 if (column > 0) { 180 if (column > 0) {
@@ -459,6 +461,7 @@ struct dnode **list_dir(char *path)
459 dir = opendir(path); 461 dir = opendir(path);
460 if (dir == NULL) { 462 if (dir == NULL) {
461 errorMsg("%s: %s\n", path, strerror(errno)); 463 errorMsg("%s: %s\n", path, strerror(errno));
464 status = EXIT_FAILURE;
462 return(NULL); /* could not open the dir */ 465 return(NULL); /* could not open the dir */
463 } 466 }
464 while ((entry = readdir(dir)) != NULL) { 467 while ((entry = readdir(dir)) != NULL) {
@@ -477,6 +480,7 @@ struct dnode **list_dir(char *path)
477 if (follow_links == TRUE) { 480 if (follow_links == TRUE) {
478 if (stat(cur->fullname, &cur->dstat)) { 481 if (stat(cur->fullname, &cur->dstat)) {
479 errorMsg("%s: %s\n", cur->fullname, strerror(errno)); 482 errorMsg("%s: %s\n", cur->fullname, strerror(errno));
483 status = EXIT_FAILURE;
480 free(cur->fullname); 484 free(cur->fullname);
481 free(cur); 485 free(cur);
482 continue; 486 continue;
@@ -485,6 +489,7 @@ struct dnode **list_dir(char *path)
485#endif 489#endif
486 if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */ 490 if (lstat(cur->fullname, &cur->dstat)) { /* get file stat info into node */
487 errorMsg("%s: %s\n", cur->fullname, strerror(errno)); 491 errorMsg("%s: %s\n", cur->fullname, strerror(errno));
492 status = EXIT_FAILURE;
488 free(cur->fullname); 493 free(cur->fullname);
489 free(cur); 494 free(cur);
490 continue; 495 continue;
@@ -791,6 +796,7 @@ extern int ls_main(int argc, char **argv)
791 if (follow_links == TRUE) { 796 if (follow_links == TRUE) {
792 if (stat(av[oi], &cur->dstat)) { 797 if (stat(av[oi], &cur->dstat)) {
793 errorMsg("%s: %s\n", av[oi], strerror(errno)); 798 errorMsg("%s: %s\n", av[oi], strerror(errno));
799 status = EXIT_FAILURE;
794 free(cur->fullname); 800 free(cur->fullname);
795 free(cur); 801 free(cur);
796 continue; 802 continue;
@@ -799,6 +805,7 @@ extern int ls_main(int argc, char **argv)
799#endif 805#endif
800 if (lstat(av[oi], &cur->dstat)) { /* get file info into node */ 806 if (lstat(av[oi], &cur->dstat)) { /* get file info into node */
801 errorMsg("%s: %s\n", av[oi], strerror(errno)); 807 errorMsg("%s: %s\n", av[oi], strerror(errno));
808 status = EXIT_FAILURE;
802 free(cur->fullname); 809 free(cur->fullname);
803 free(cur); 810 free(cur);
804 continue; 811 continue;
@@ -842,7 +849,7 @@ extern int ls_main(int argc, char **argv)
842 } 849 }
843 } 850 }
844 851
845 return(0); 852 return(status);
846 853
847 print_usage_message: 854 print_usage_message:
848 usage(ls_usage); 855 usage(ls_usage);