start hw6
authorkremlin <ian@kremlin.cc>
Thu, 9 Oct 2014 17:36:25 +0000 (13:36 -0400)
committerkremlin <ian@kremlin.cc>
Thu, 9 Oct 2014 17:36:25 +0000 (13:36 -0400)
assgn6/filewatch.c [new file with mode: 0644]

diff --git a/assgn6/filewatch.c b/assgn6/filewatch.c
new file mode 100644 (file)
index 0000000..3c0bc67
--- /dev/null
@@ -0,0 +1,52 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <errno.h>
+
+int main(int argc, char *argv[]) {
+
+    char *lex_path;
+    DIR  *path;
+    struct dirent *dent;
+
+    extern int errno;
+
+    if(argc == 1)
+        lex_path = "./";
+
+    else if(argc == 2)
+        lex_path = argv[1];
+
+    else {
+
+        printf("inappropriate number of args.\n");
+        return 1;
+    }
+
+    if(!(path = opendir(path))) {
+
+        if(errno == EACCES)
+            printf("improper permissions to read dir.\n");
+
+        else if(errno == ENOENT)
+            printf("given directory does not exist.\n");
+
+        else if(errno == ENFILE)
+            printf("we're out of fd's.\n");
+
+        else if(errno == ENOTDIR)
+            printf("argument is not a directory.\n");
+
+        else
+            printf("an unspecified error occurred.\n");
+
+        return errno;
+    }
+
+    if((dent = readdir(path)) != NULL) {
+
+        if(
+    }
+
+    return 0;
+}