commit c595ac747c58a8d8a26b526d6f57fe8ddda27d9b
parent c12b753082d2517656015ad78fcce9808016e508
Author: Ed van Bruggen <edvb54@gmail.com>
Date: Fri, 18 Aug 2017 16:46:05 -0700
Error check fopen
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/nt.c b/nt.c
@@ -248,7 +248,8 @@ setup(void)
/* load file if it exists */
if (access(fname, F_OK) != -1) {
- fp = fopen(fname, "r");
+ if (!(fp = fopen(fname, "r")))
+ die("%s: %s:", argv0, fname);
while (fscanf(fp, "%2048[^\n]\n", buf) != EOF)
linkadd(buf);
fclose(fp);
@@ -266,7 +267,8 @@ cleanup(void)
Note *cur = head;
/* write note list to file */
- fp = fopen(fname, "w");
+ if (!(fp = fopen(fname, "w")))
+ die("%s: %s:", argv0, fname);
for (; cur; cur = cur->next)
if (cur->str)
fprintf(fp, "%s\n", cur->str);