about summary refs log tree commit diff
path: root/templates
diff options
context:
space:
mode:
authorlukasepple <git@lukasepple.de>2014-08-08 10:54:39 +0200
committerlukasepple <git@lukasepple.de>2014-08-08 10:54:39 +0200
commit72cb58a952d6a86ec41f63856accf4fc6172795e (patch)
treeaf1c276304dd3221480ac38ff0d8ef3abf68c712 /templates
parent66ee3afdcd2136dd04265ccbecb7d231e0246f5d (diff)
error checking
Diffstat (limited to 'templates')
-rw-r--r--templates/simple.c12
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) {