aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-11-23 12:02:44 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-11-23 12:02:44 +0100
commit59b4f6b33bfa602c4f0412623e8b76194a852de5 (patch)
tree9540f86e7cf844b8a90dd5f9172363e4239ee18f
parentff75f849823cc397809000a7abea6cb4a47ac046 (diff)
Improved RemHist()
-rw-r--r--FICS/gamedb.c29
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);
}
}