]> git.seodisparate.com - c_simple_http/commitdiff
Check if fopen() fails during generating html
authorStephen Seo <seo.disparate@gmail.com>
Sun, 10 Nov 2024 11:47:56 +0000 (20:47 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sun, 10 Nov 2024 11:47:56 +0000 (20:47 +0900)
src/main.c

index 9a8f63a3a7cfb4ca0c2556ff3626294f64f5f098..1f8466e37987231a2cbd188b7606ff39d530c764 100644 (file)
@@ -450,6 +450,12 @@ int generate_paths_fn(const void *key,
 
   // Save the html.
   FILE *fd = fopen(generated_path, "wb");
+  if (!fd) {
+    fprintf(stderr,
+            "WARNING Failed to open \"%s\" for writing, skipping!\n",
+            generated_path);
+    return 0;
+  }
   unsigned long fwrite_ret = fwrite(html_buf, 1, html_buf_size, fd);
   if (fwrite_ret < html_buf_size) {
     fclose(fd);