aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2011-10-16 18:14:51 +0100
committerConnor Lane Smith <cls@lubutu.com>2011-10-16 18:14:51 +0100
commitc71abdc65c8a7ff9597f7b6b5bf60a59be174224 (patch)
treeb946a4b362fd8f86d7cbaebb2bf74fd5a24db934
parent4126b1e32379ee206c5c9bda2bf3699f171c9899 (diff)
lsx: return failure on error
-rw-r--r--lsx.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lsx.c b/lsx.c
index f337a4a..57c03bf 100644
--- a/lsx.c
+++ b/lsx.c
@@ -8,6 +8,8 @@
8 8
9static void lsx(const char *dir); 9static void lsx(const char *dir);
10 10
11static int status = EXIT_SUCCESS;
12
11int 13int
12main(int argc, char *argv[]) { 14main(int argc, char *argv[]) {
13 int i; 15 int i;
@@ -16,7 +18,7 @@ main(int argc, char *argv[]) {
16 lsx("."); 18 lsx(".");
17 else for(i = 1; i < argc; i++) 19 else for(i = 1; i < argc; i++)
18 lsx(argv[i]); 20 lsx(argv[i]);
19 return EXIT_SUCCESS; 21 return status;
20} 22}
21 23
22void 24void
@@ -27,12 +29,13 @@ lsx(const char *dir) {
27 DIR *dp; 29 DIR *dp;
28 30
29 if(!(dp = opendir(dir))) { 31 if(!(dp = opendir(dir))) {
32 status = EXIT_FAILURE;
30 perror(dir); 33 perror(dir);
31 return; 34 return;
32 } 35 }
33 while((d = readdir(dp))) 36 while((d = readdir(dp)))
34 if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < (int)sizeof buf 37 if(snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name) < (int)sizeof buf
35 && !stat(buf, &st) && S_ISREG(st.st_mode) && access(buf, X_OK) == 0) 38 && stat(buf, &st) == 0 && S_ISREG(st.st_mode) && access(buf, X_OK) == 0)
36 puts(d->d_name); 39 puts(d->d_name);
37 closedir(dp); 40 closedir(dp);
38} 41}