lsx: return failure on error c71abdc6
Connor Lane Smith · 2011-10-16 18:14 1 file(s) · +5 −2
lsx.c +5 −2
8 8
9 9
static void lsx(const char *dir);
10 10
11 +
static int status = EXIT_SUCCESS;
12 +
11 13
int
12 14
main(int argc, char *argv[]) {
13 15
	int i;
16 18
		lsx(".");
17 19
	else for(i = 1; i < argc; i++)
18 20
		lsx(argv[i]);
19 -
	return EXIT_SUCCESS;
21 +
	return status;
20 22
}
21 23
22 24
void
27 29
	DIR *dp;
28 30
29 31
	if(!(dp = opendir(dir))) {
32 +
		status = EXIT_FAILURE;
30 33
		perror(dir);
31 34
		return;
32 35
	}
33 36
	while((d = readdir(dp)))
34 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 39
			puts(d->d_name);
37 40
	closedir(dp);
38 41
}