diff options
author | Connor Lane Smith <cls@lubutu.com> | 2011-10-16 18:14:51 +0100 |
---|---|---|
committer | Connor Lane Smith <cls@lubutu.com> | 2011-10-16 18:14:51 +0100 |
commit | c71abdc65c8a7ff9597f7b6b5bf60a59be174224 (patch) | |
tree | b946a4b362fd8f86d7cbaebb2bf74fd5a24db934 | |
parent | 4126b1e32379ee206c5c9bda2bf3699f171c9899 (diff) |
lsx: return failure on error
-rw-r--r-- | lsx.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -8,6 +8,8 @@ | |||
8 | 8 | ||
9 | static void lsx(const char *dir); | 9 | static void lsx(const char *dir); |
10 | 10 | ||
11 | static int status = EXIT_SUCCESS; | ||
12 | |||
11 | int | 13 | int |
12 | main(int argc, char *argv[]) { | 14 | main(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 | ||
22 | void | 24 | void |
@@ -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 | } |