diff options
author | lukasepple <git@lukasepple.de> | 2014-08-08 10:54:39 +0200 |
---|---|---|
committer | lukasepple <git@lukasepple.de> | 2014-08-08 10:54:39 +0200 |
commit | 72cb58a952d6a86ec41f63856accf4fc6172795e (patch) | |
tree | af1c276304dd3221480ac38ff0d8ef3abf68c712 /templates | |
parent | 66ee3afdcd2136dd04265ccbecb7d231e0246f5d (diff) |
error checking
Diffstat (limited to 'templates')
-rw-r--r-- | templates/simple.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/templates/simple.c b/templates/simple.c index 6754bc1..72e8be3 100644 --- a/templates/simple.c +++ b/templates/simple.c @@ -22,6 +22,13 @@ void template_footer(void) { void template_post_single_entry(struct blogpost post) { FILE *fp = fopen(post.path, "r"); char c; + + if(fp == NULL) { + template_error_404(); + exit(EXIT_SUCCESS); + /* TODO: does CGI still work correctly if we exit + * with EXIT_FAILURE? */ + } printf("<article>\n"); @@ -38,6 +45,11 @@ void template_post_index_entry(struct blogpost post) { FILE *fp = fopen(post.path, "r"); char c; + if(fp == NULL) { + fprintf(stderr, "No such file or directory: %s\n", post.path); + exit(EXIT_FAILURE); + } + printf("<article>\n"); while((c = fgetc(fp)) != EOF) { |