diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-12-02 13:34:11 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-12-02 13:34:11 +0100 |
commit | 4afb8631a62b0811719495d0656861c625251433 (patch) | |
tree | 50d53f78d1eb6a1812e9cca28451410813a3c557 | |
parent | 2d139b5a28a9e65d60e44c46790828991960586a (diff) |
Fixed bugs in game_write_complete()
-rw-r--r-- | FICS/gamedb.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/FICS/gamedb.c b/FICS/gamedb.c index bf9dfbe..9644834 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -2121,9 +2121,9 @@ pgames(int p, int p1, char *fname) PUBLIC void game_write_complete(int g, int isDraw, char *EndSymbol) { - FILE *fp; + FILE *fp = NULL; char fname[MAX_FILENAME_SIZE] = { '\0' }; - int fd; + int fd = -1; int wp = garray[g].white, bp = garray[g].black; time_t now = time(NULL); @@ -2132,20 +2132,21 @@ game_write_complete(int g, int isDraw, char *EndSymbol) hist_dir, (long int)(now % 100), (long int)now); + errno = 0; fd = open(fname, (O_WRONLY | O_CREAT | O_EXCL), 0644); - if (fd == EEXIST) + if (fd == -1 && errno == EEXIST) now++; - } while (fd == EEXIST); + } while (fd == -1 && errno == EEXIST); if (fd >= 0) { - fp = fdopen(fd, "w"); - if (fp != NULL) + if ((fp = fdopen(fd, "w")) != NULL) { WriteGameFile(fp, g); - else { + fclose(fp); + } else { fprintf(stderr, "Trouble writing history file %s", fname); } - fclose(fp); + close(fd); } |