[hackers] [sbase] ls: do not exit when a directory isn't accessible || Quentin Rameau

From: <git_AT_suckless.org>
Date: Thu, 18 Feb 2016 12:32:02 +0100 (CET)

commit 340b1635631b08be4554d937cf5895194b4733d6
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Feb 18 12:06:21 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Thu Feb 18 11:31:58 2016 +0000

    ls: do not exit when a directory isn't accessible
    
    Just print a warning and process next item instead,
    and return 1 to report this error.

diff --git a/ls.c b/ls.c
index 72d7434..f5b3e76 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -32,6 +32,7 @@ static struct {
         ino_t ino;
 } tree[PATH_MAX];
 
+static int ret = 0;
 static int Aflag = 0;
 static int aflag = 0;
 static int cflag = 0;
_AT_@ -247,8 +248,11 @@ lsdir(const char *path, const struct entry *dir)
         size_t i, n = 0;
         char prefix[PATH_MAX];
 
- if (!(dp = opendir(dir->name)))
- eprintf("opendir %s:", dir->name);
+ if (!(dp = opendir(dir->name))) {
+ ret = 1;
+ weprintf("opendir %s:", dir->name);
+ return;
+ }
         if (chdir(dir->name) < 0)
                 eprintf("chdir %s:", dir->name);
 
_AT_@ -474,5 +478,5 @@ main(int argc, char *argv[])
                 free(dents);
         }
 
- return fshut(stdout, "<stdout>");
+ return (fshut(stdout, "<stdout>") | ret);
 }
Received on Thu Feb 18 2016 - 12:32:02 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 18 2016 - 12:36:12 CET