aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-03-16 23:02:57 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-03-16 23:03:43 +1300
commit6522895fdf6d741a64f75e3ee7fe24b6f354eaa7 (patch)
treed84689fa25547505a22c81703dbf5309d12849f0
parentls(1) accepts one argument (diff)
downloadtunics-6522895fdf6d741a64f75e3ee7fe24b6f354eaa7.tar.gz
tunics-6522895fdf6d741a64f75e3ee7fe24b6f354eaa7.zip
Some basic ls(1) error checking
-rw-r--r--ls.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ls.c b/ls.c
index 4b48c9c..251d5fb 100644
--- a/ls.c
+++ b/ls.c
@@ -1,4 +1,5 @@
#include <dirent.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -15,11 +16,18 @@ int main(int argc, char **argv)
dirname = ".";
}
- dir = opendir(dirname);
+ if ((dir = opendir(dirname)) == NULL) {
+ perror("opendir");
+ exit(EXIT_FAILURE);
+ }
while ((dirent = readdir(dir)) != NULL) {
fprintf(stdout, "%s\n", dirent->d_name);
}
+ if (errno) {
+ perror("readdir");
+ exit(EXIT_FAILURE);
+ }
exit(EXIT_SUCCESS);
}