From 57114336670264eae04a595013403188e63ba58e Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Thu, 2 May 2024 22:37:46 +0200 Subject: Revised OldestHistGame() --- FICS/gamedb.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 555bf8e..4fc6d0e 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1256,28 +1256,31 @@ PUBLIC int game_save(int g) return 0; } -PRIVATE long OldestHistGame(char *login) +PRIVATE long int +OldestHistGame(char *login) { - FILE *fp; - char pFile[MAX_FILENAME_SIZE]; - long when; - - sprintf(pFile, "%s/player_data/%c/%s.%s", stats_dir, - login[0], login, STATS_GAMES); - fp = fopen(pFile, "r"); + FILE *fp; + char pFile[MAX_FILENAME_SIZE] = { '\0' }; + long int when; - if (fp == NULL) { - sprintf(pFile, "%s/player_data/%c/.rem.%s.%s", stats_dir, + msnprintf(pFile, sizeof pFile, "%s/player_data/%c/%s.%s", stats_dir, login[0], login, STATS_GAMES); - fp = fopen(pFile, "r"); - } - if (fp != NULL) { - fscanf(fp, "%*d %*c %*d %*c %*d %*s %*s %*d %*d %*d %*d %*s %*s %ld", - &when); - fclose(fp); - return when; - } else - return 0L; + + fp = fopen(pFile, "r"); + + if (fp == NULL) { + msnprintf(pFile, sizeof pFile, "%s/player_data/%c/.rem.%s.%s", + stats_dir, login[0], login, STATS_GAMES); + fp = fopen(pFile, "r"); + } + + if (fp != NULL) { + fscanf(fp, "%*d %*c %*d %*c %*d %*s %*s %*d %*d %*d %*d %*s " + "%*s %ld", &when); + fclose(fp); + return when; + } else + return 0L; } PRIVATE void -- cgit v1.2.3