diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-19 12:05:40 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-19 12:05:40 +0200 |
commit | 0d61674e7a766818bed421e4a99499ba2ec79bd1 (patch) | |
tree | cca39b52b6c1c6dfdc8c44fbd146a0b6b21357c4 /FICS/adminproc.c | |
parent | 8b3a744d1170afbce1f8a8d363d9809cf29f8814 (diff) |
Revised add_item()
Diffstat (limited to 'FICS/adminproc.c')
-rw-r--r-- | FICS/adminproc.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c index 883f5bc..a0c0c4a 100644 --- a/FICS/adminproc.c +++ b/FICS/adminproc.c @@ -161,32 +161,37 @@ PRIVATE int create_news_file(int p, param_list param, int admin) return COM_OK; } -PRIVATE int add_item(char *new_item, char *filename) +PRIVATE int +add_item(char *new_item, char *filename) { - FILE *new_fp, *old_fp; - char tmp_file[MAX_FILENAME_SIZE]; - char junk[MAX_LINE_SIZE]; - - sprintf(tmp_file, "%s/.tmp.idx", news_dir); - new_fp = fopen(tmp_file, "w"); - old_fp = fopen(filename, "r"); - - if (!new_fp || !old_fp) - return 0; - - fprintf(new_fp, "%s", new_item); - while (1) { - fgets(junk, MAX_LINE_SIZE, old_fp); - if (feof(old_fp)) - break; - fprintf(new_fp, "%s", junk); - } - fclose(new_fp); - fclose(old_fp); - remove(filename); - rename(tmp_file, filename); + FILE *new_fp, *old_fp; + char junk[MAX_LINE_SIZE] = { '\0' }; + char tmp_file[MAX_FILENAME_SIZE] = { '\0' }; + + sprintf(tmp_file, "%s/.tmp.idx", news_dir); + + new_fp = fopen(tmp_file, "w"); + old_fp = fopen(filename, "r"); + + if (!new_fp || !old_fp) + return 0; + + fprintf(new_fp, "%s", new_item); + + while (1) { + fgets(junk, MAX_LINE_SIZE, old_fp); + + if (feof(old_fp)) + break; + fprintf(new_fp, "%s", junk); + } + + fclose(new_fp); + fclose(old_fp); + remove(filename); + rename(tmp_file, filename); - return 1; + return 1; } /* |