From 6ce020240b1dd356a32d3b1a2288f6efb98bf1f4 Mon Sep 17 00:00:00 2001 From: Elliott Pardee Date: Fri, 12 Jun 2015 04:23:06 -0400 Subject: [PATCH] some error checking --- c/typeprint.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/c/typeprint.c b/c/typeprint.c index 3c65c14..3af0605 100644 --- a/c/typeprint.c +++ b/c/typeprint.c @@ -2,6 +2,7 @@ #include #include #include +#include static int process(char *name); @@ -14,11 +15,16 @@ process(char *name) ts.tv_sec = 0; ts.tv_nsec = 10 * 1000000; - if (file == 0) { + if (access(file, F_OK) = -1) { fprintf(stderr, "[err] no such file or directory\n"); return ENOENT; } + if (access(file, R_OK) = -1) { + fprintf(stderr, "[err] can't read file, permission denied\n"); + return EACCES; + } + int x; while ((x = fgetc(file)) != EOF) { printf("%c", x);