diff options
-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; |