OSDN Git Service

Since struct dirent only holds the last element in the path, build the full path...
authorEric Branlund <ebranlund@fastmail.com>
Fri, 5 Feb 2021 23:06:42 +0000 (15:06 -0800)
committerEric Branlund <ebranlund@fastmail.com>
Fri, 5 Feb 2021 23:06:42 +0000 (15:06 -0800)
src/main/angband-initializer.c

index 666562a..25f6967 100644 (file)
@@ -131,16 +131,18 @@ void init_file_paths(char *libpath, char *varpath)
             struct dirent *next_entry;
 
             while ((next_entry = readdir(saves_dir))) {
-                const char *dash_loc = angband_strchr(next_entry->d_name, '-');
-                struct stat next_stat;
+                if (angband_strchr(next_entry->d_name, '-')) {
+                    char path[1024];
+                    struct stat next_stat;
 
-                if (dash_loc && stat(next_entry->d_name, &next_stat) == 0) {
+                    path_build(path, sizeof(path), ANGBAND_DIR_DEBUG_SAVE, next_entry->d_name);
                     /*
                      * Remove if modified more than a week ago,
                      * 7*24*60*60 seconds.
                      */
-                    if (difftime(now, next_stat.st_mtime) > 604800) {
-                        remove(next_entry->d_name);
+                    if (stat(path, &next_stat) == 0 &&
+                            difftime(now, next_stat.st_mtime) > 604800) {
+                        remove(path);
                     }
                 }
             }