OSDN Git Service

[Refactor] #3281 fd_open() の引数をstring_view からpath に差し替えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 11 May 2023 11:27:27 +0000 (20:27 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 13 May 2023 12:56:20 +0000 (21:56 +0900)
src/core/game-closer.cpp
src/core/game-play.cpp
src/core/scores.cpp
src/io/files-util.cpp
src/io/record-play-movie.cpp
src/load/load.cpp
src/main-win.cpp
src/main-x11.cpp
src/main/angband-initializer.cpp
src/util/angband-files.cpp
src/util/angband-files.h

index 9aa089e..758fa18 100644 (file)
@@ -152,7 +152,7 @@ void close_game(PlayerType *player_ptr)
     w_ptr->character_icky_depth = 1;
     const auto &path = path_build(ANGBAND_DIR_APEX, "scores.raw");
     safe_setuid_grab(player_ptr);
-    highscore_fd = fd_open(path.string(), O_RDWR);
+    highscore_fd = fd_open(path, O_RDWR);
     safe_setuid_drop();
 
     if (!check_death(player_ptr)) {
index 0bb52a9..b78c1a0 100644 (file)
@@ -130,7 +130,7 @@ static void send_waiting_record(PlayerType *player_ptr)
     signals_ignore_tstp();
     w_ptr->character_icky_depth = 1;
     const auto &path = path_build(ANGBAND_DIR_APEX, "scores.raw");
-    highscore_fd = fd_open(path.string(), O_RDWR);
+    highscore_fd = fd_open(path, O_RDWR);
 
     /* 町名消失バグ対策(#38205)のためここで世界マップ情報を読み出す */
     parse_fixed_map(player_ptr, WILDERNESS_DEFINITION, 0, 0, w_ptr->max_wild_y, w_ptr->max_wild_x);
index 41dad18..396fccb 100644 (file)
@@ -360,7 +360,7 @@ void show_highclass(PlayerType *player_ptr)
 {
     screen_save();
     const auto &path = path_build(ANGBAND_DIR_APEX, "scores.raw");
-    highscore_fd = fd_open(path.string(), O_RDONLY);
+    highscore_fd = fd_open(path, O_RDONLY);
     if (highscore_fd < 0) {
         msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
         msg_print(nullptr);
@@ -439,7 +439,7 @@ void race_score(PlayerType *player_ptr, int race_num)
     /* rr9: TODO - pluralize the race */
     prt(std::string(_("最高の", "The Greatest of all the ")).append(race_info[race_num].title), 5, 15);
     const auto &path = path_build(ANGBAND_DIR_APEX, "scores.raw");
-    highscore_fd = fd_open(path.string(), O_RDONLY);
+    highscore_fd = fd_open(path, O_RDONLY);
     if (highscore_fd < 0) {
         msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
         msg_print(nullptr);
index 3311143..ad2b581 100644 (file)
@@ -58,9 +58,9 @@ std::filesystem::path debug_savefile;
 errr file_character(PlayerType *player_ptr, concptr name)
 {
     const auto &path = path_build(ANGBAND_DIR_USER, name);
-    const auto &filename = path.string();
-    auto fd = fd_open(filename, O_RDONLY);
+    auto fd = fd_open(path, O_RDONLY);
     if (fd >= 0) {
+        const auto &filename = path.string();
         std::string query = _("現存するファイル ", "Replace existing file ");
         query.append(filename).append(_(" に上書きしますか? ", "? "));
         (void)fd_close(fd);
@@ -265,7 +265,7 @@ static errr counts_seek(PlayerType *player_ptr, int fd, uint32_t where, bool fla
 uint32_t counts_read(PlayerType *player_ptr, int where)
 {
     const auto &path = path_build(ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
-    auto fd = fd_open(path.string(), O_RDONLY);
+    auto fd = fd_open(path, O_RDONLY);
     uint32_t count = 0;
     if (counts_seek(player_ptr, fd, where, false) || fd_read(fd, (char *)(&count), sizeof(uint32_t))) {
         count = 0;
@@ -287,7 +287,7 @@ errr counts_write(PlayerType *player_ptr, int where, uint32_t count)
 {
     const auto &path = path_build(ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
     safe_setuid_grab(player_ptr);
-    auto fd = fd_open(path.string(), O_RDWR);
+    auto fd = fd_open(path, O_RDWR);
     safe_setuid_drop();
     if (fd < 0) {
         safe_setuid_grab(player_ptr);
index b6be495..c483913 100644 (file)
@@ -353,9 +353,9 @@ void prepare_movie_hooks(PlayerType *player_ptr)
     }
 
     const auto &path = path_build(ANGBAND_DIR_USER, movie_filename);
-    const auto &filename = path.string();
-    auto fd = fd_open(filename, O_RDONLY);
+    auto fd = fd_open(path, O_RDONLY);
     if (fd >= 0) {
+        const auto &filename = path.string();
         (void)fd_close(fd);
         std::string query = _("現存するファイルに上>書きしますか? (", "Replace existing file ");
         query.append(filename);
@@ -364,7 +364,7 @@ void prepare_movie_hooks(PlayerType *player_ptr)
             return;
         }
 
-        movie_fd = fd_open(filename, O_WRONLY | O_TRUNC);
+        movie_fd = fd_open(path, O_WRONLY | O_TRUNC);
     } else {
         movie_fd = fd_make(path);
     }
index a733b8f..e09d2fb 100644 (file)
@@ -368,7 +368,7 @@ bool load_savedata(PlayerType *player_ptr, bool *new_game)
     constexpr auto version_length = variant_length + 6;
     char tmp_ver[version_length]{};
     if (!err) {
-        fd = fd_open(savefile_str.data(), O_RDONLY);
+        fd = fd_open(savefile, O_RDONLY);
         if (fd < 0) {
             err = true;
         }
index df513b8..2520fbc 100644 (file)
@@ -1647,7 +1647,7 @@ static void process_menus(PlayerType *player_ptr, WORD wCmd)
     }
     case IDM_FILE_SCORE: {
         const auto &path = path_build(ANGBAND_DIR_APEX, "scores.raw");
-        highscore_fd = fd_open(path.string(), O_RDONLY);
+        highscore_fd = fd_open(path, O_RDONLY);
         if (highscore_fd < 0) {
             msg_print("Score file unavailable.");
         } else {
index 1afd33e..75ed0a5 100644 (file)
@@ -2516,8 +2516,7 @@ errr init_x11(int argc, char *argv[])
     switch (arg_graphics) {
     case GRAPHICS_ORIGINAL: {
         const auto &path = path_build(ANGBAND_DIR_XTRA, "graf/8x8.bmp");
-        const auto &filename = path.string();
-        if (0 == fd_close(fd_open(filename, O_RDONLY))) {
+        if (0 == fd_close(fd_open(path, O_RDONLY))) {
             use_graphics = true;
             pict_wid = pict_hgt = 8;
             ANGBAND_GRAF = "old";
@@ -2526,8 +2525,7 @@ errr init_x11(int argc, char *argv[])
     }
     case GRAPHICS_ADAM_BOLT: {
         const auto &path = path_build(ANGBAND_DIR_XTRA, "graf/16x16.bmp");
-        const auto &filename = path.string();
-        if (0 == fd_close(fd_open(filename, O_RDONLY))) {
+        if (0 == fd_close(fd_open(path, O_RDONLY))) {
             use_graphics = true;
             pict_wid = pict_hgt = 16;
             ANGBAND_GRAF = "new";
index fcd7c6b..7b66647 100644 (file)
@@ -163,7 +163,7 @@ static void put_title()
 void init_angband(PlayerType *player_ptr, bool no_term)
 {
     const auto &path_news = path_build(ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
-    auto fd = fd_open(path_news.string(), O_RDONLY);
+    auto fd = fd_open(path_news, O_RDONLY);
     if (fd < 0) {
         std::string why = _("'", "Cannot access the '");
         why.append(path_news.string());
@@ -189,13 +189,13 @@ void init_angband(PlayerType *player_ptr, bool no_term)
     }
 
     const auto &path_score = path_build(ANGBAND_DIR_APEX, "scores.raw");
-    const auto &filename_score = path_score.string();
-    fd = fd_open(filename_score, O_RDONLY);
+    fd = fd_open(path_score, O_RDONLY);
     if (fd < 0) {
         safe_setuid_grab(player_ptr);
         fd = fd_make(path_score, true);
         safe_setuid_drop();
         if (fd < 0) {
+            const auto &filename_score = path_score.string();
             std::string why = _("'", "Cannot create the '");
             why.append(filename_score);
             why.append(_("'ファイルを作成できません!", "' file!"));
index c6059c2..6e14288 100644 (file)
@@ -392,13 +392,13 @@ int fd_make(const std::filesystem::path &path, bool can_write_group)
 
 /*
  * @brief OSごとの差異を吸収してファイルを開く
- * @param file ファイルの相対パスまたは絶対パス
+ * @param path ファイルの相対パスまたは絶対パス
  * @param mode ファイルのオープンモード (読み書き、Append/Trunc等)
  */
-int fd_open(std::string_view file, int mode)
+int fd_open(const std::filesystem::path &path, int mode)
 {
-    const auto &path = path_parse(file);
-    return open(path.string().data(), mode | O_BINARY, 0);
+    const auto &path_abs = path_parse(path);
+    return open(path_abs.string().data(), mode | O_BINARY, 0);
 }
 
 /*
index 3b4547f..fb00f3e 100644 (file)
@@ -51,7 +51,7 @@ errr angband_fclose(FILE *fff);
 void fd_kill(const std::filesystem::path &path);
 void fd_move(std::string_view from, std::string_view to);
 int fd_make(const std::filesystem::path &path, bool can_write_group = false);
-int fd_open(std::string_view file, int mode);
+int fd_open(const std::filesystem::path &path, int mode);
 errr fd_lock(int fd, int what);
 errr fd_seek(int fd, ulong n);
 errr fd_read(int fd, char *buf, ulong n);