diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-11-23 12:02:44 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-11-23 12:02:44 +0100 |
commit | 59b4f6b33bfa602c4f0412623e8b76194a852de5 (patch) | |
tree | 9540f86e7cf844b8a90dd5f9172363e4239ee18f /FICS | |
parent | ff75f849823cc397809000a7abea6cb4a47ac046 (diff) |
Improved RemHist()
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/gamedb.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 598c2c2..4437637 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1650,22 +1650,37 @@ RemHist(char *who) msnprintf(fName, sizeof fName, "%s/player_data/%c/%s.%s", stats_dir, who[0], who, STATS_GAMES); - fp = fopen(fName, "r"); + if ((fp = fopen(fName, "r")) != NULL) { + long int line_no = 0; - if (fp != NULL) { while (!feof(fp)) { - fscanf(fp, "%*d %*c %*d %*c %*d %s %*s %*d %*d %*d " - "%*d %*s %*s %ld", Opp, &When); + const int ret = fscanf(fp, "%*d %*c %*d %*c %*d %19s " + "%*s %*d %*d %*d %*d %*s %*s %ld", Opp, &When); + if (ret != 2) { + warnx("%s: fscanf() error (%s:%ld)", __func__, + fName, line_no); + line_no++; + continue; + } stolower(Opp); oppWhen = OldestHistGame(Opp); if (oppWhen > When || oppWhen <= 0L) { - msnprintf(fName, sizeof fName, "%s/%ld/%ld", - hist_dir, When % 100, When); - unlink(fName); + char histfile[MAX_FILENAME_SIZE] = { '\0' }; + + msnprintf(histfile, sizeof histfile, + "%s/%ld/%ld", hist_dir, (When % 100), When); + if (unlink(histfile) != 0) { + warn("%s: unlink(%s)", __func__, + histfile); + } } + + line_no++; } + + fclose(fp); } } |