diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-20 02:52:54 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-20 02:55:21 +0200 |
commit | acc3e1bcd5460c709d9f18c07079fe4a6b8d9846 (patch) | |
tree | 519db38e0a9b56b42987bef976ceab6055399ac0 /FICS | |
parent | b893b787cf33db7b9672b44c31066224b5cfd70e (diff) |
add_item: allow non-existent old file
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/adminproc.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c index 8f81448..32746e7 100644 --- a/FICS/adminproc.c +++ b/FICS/adminproc.c @@ -211,14 +211,13 @@ add_item(char *new_item, char *filename) msnprintf(tmp_file, sizeof tmp_file, "%s/.tmp.idx", news_dir); - new_fp = fopen(tmp_file, "w"); - old_fp = fopen(filename, "r"); - - if (!new_fp || !old_fp) + if ((new_fp = fopen(tmp_file, "w")) == NULL) return 0; - fprintf(new_fp, "%s", new_item); + if ((old_fp = fopen(filename, "r")) == NULL) + goto end; + while (1) { fgets(junk, MAX_LINE_SIZE, old_fp); @@ -227,9 +226,12 @@ add_item(char *new_item, char *filename) fprintf(new_fp, "%s", junk); } + end: fclose(new_fp); - fclose(old_fp); - remove(filename); + if (old_fp) { + fclose(old_fp); + remove(filename); + } rename(tmp_file, filename); return 1; |