diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-01 16:55:28 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-01 16:55:28 +0200 |
commit | 615c311773084292357739e0205f900bcf6dce79 (patch) | |
tree | 555bffdafc9580d78e794ab049b73c8093b2943b /FICS/gamedb.c | |
parent | 8a8af59d2dbbed442196a7002384e0f197c90a70 (diff) |
Revised game_write_complete()
Diffstat (limited to 'FICS/gamedb.c')
-rw-r--r-- | FICS/gamedb.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/FICS/gamedb.c b/FICS/gamedb.c index ce3d69f..1140fd4 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1700,36 +1700,50 @@ PUBLIC int pgames(int p, int p1, char *fname) return COM_OK; } -PUBLIC void game_write_complete(int g, int isDraw, char *EndSymbol) +PUBLIC void +game_write_complete(int g, int isDraw, char *EndSymbol) { - char fname[MAX_FILENAME_SIZE]; - int wp = garray[g].white, bp = garray[g].black; - time_t now = time(NULL); - int fd; - FILE *fp; + FILE *fp; + char fname[MAX_FILENAME_SIZE] = { '\0' }; + int fd; + int wp = garray[g].white, bp = garray[g].black; + time_t now = time(NULL); + + do { + msnprintf(fname, sizeof fname, "%s/%ld/%ld", + hist_dir, + (long int)(now % 100), + (long int)now); + fd = open(fname, (O_WRONLY | O_CREAT | O_EXCL), 0644); + if (fd == EEXIST) + now++; + } while (fd == EEXIST); + + if (fd >= 0) { + fp = fdopen(fd, "w"); + if (fp != NULL) + WriteGameFile(fp, g); + else { + fprintf(stderr, "Trouble writing history file %s", + fname); + } + fclose(fp); + close(fd); + } - do { - sprintf(fname, "%s/%ld/%ld", hist_dir, (long) now % 100, (long) now); - fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0644); - if (fd == EEXIST) - now++; - } while (fd == EEXIST); - - if (fd >= 0) { - fp = fdopen(fd, "w"); - if (fp != NULL) - WriteGameFile(fp, g); - else - fprintf(stderr, "Trouble writing history file %s", fname); - fclose(fp); - close(fd); - } - sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, - parray[wp].login[0], parray[wp].login, STATS_GAMES); - write_g_out(g, fname, 10, isDraw, EndSymbol, parray[wp].name, &now); - sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, - parray[bp].login[0], parray[bp].login, STATS_GAMES); - write_g_out(g, fname, 10, isDraw, EndSymbol, parray[bp].name, &now); + msnprintf(fname, sizeof fname, "%s/player_data/%c/%s.%s", + stats_dir, + parray[wp].login[0], + parray[wp].login, + STATS_GAMES); + write_g_out(g, fname, 10, isDraw, EndSymbol, parray[wp].name, &now); + + msnprintf(fname, sizeof fname, "%s/player_data/%c/%s.%s", + stats_dir, + parray[bp].login[0], + parray[bp].login, + STATS_GAMES); + write_g_out(g, fname, 10, isDraw, EndSymbol, parray[bp].name, &now); } PUBLIC int |