OSDN Git Service

[Refactor] #3281 fd_make() の引数をstring_view からpath に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 8 May 2023 14:30:10 +0000 (23:30 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 13 May 2023 04:38:44 +0000 (13:38 +0900)
src/floor/floor-save.cpp
src/io/files-util.cpp
src/io/record-play-movie.cpp
src/main/angband-initializer.cpp
src/save/floor-writer.cpp
src/util/angband-files.cpp
src/util/angband-files.h

index 45c0688..79629ce 100644 (file)
@@ -65,9 +65,9 @@ void init_saved_floors(PlayerType *player_ptr, bool force)
     auto fd = -1;
     for (int i = 0; i < MAX_SAVED_FLOORS; i++) {
         saved_floor_type *sf_ptr = &saved_floors[i];
-        std::string floor_savefile = get_saved_floor_name(i);
+        auto floor_savefile = get_saved_floor_name(i);
         safe_setuid_grab(player_ptr);
-        fd = fd_make(floor_savefile.data());
+        fd = fd_make(floor_savefile);
         safe_setuid_drop();
         check_saved_tmp_files(fd, &force);
         safe_setuid_grab(player_ptr);
index ea1d315..3311143 100644 (file)
@@ -291,7 +291,7 @@ errr counts_write(PlayerType *player_ptr, int where, uint32_t count)
     safe_setuid_drop();
     if (fd < 0) {
         safe_setuid_grab(player_ptr);
-        fd = fd_make(path.string());
+        fd = fd_make(path);
         safe_setuid_drop();
     }
 
index 2d87c29..b6be495 100644 (file)
@@ -366,7 +366,7 @@ void prepare_movie_hooks(PlayerType *player_ptr)
 
         movie_fd = fd_open(filename, O_WRONLY | O_TRUNC);
     } else {
-        movie_fd = fd_make(filename);
+        movie_fd = fd_make(path);
     }
 
     if (!movie_fd) {
index f9e1ffc..fcd7c6b 100644 (file)
@@ -193,7 +193,7 @@ void init_angband(PlayerType *player_ptr, bool no_term)
     fd = fd_open(filename_score, O_RDONLY);
     if (fd < 0) {
         safe_setuid_grab(player_ptr);
-        fd = fd_make(filename_score, true);
+        fd = fd_make(path_score, true);
         safe_setuid_drop();
         if (fd < 0) {
             std::string why = _("'", "Cannot create the '");
index 02c31ea..c8172a2 100644 (file)
@@ -257,7 +257,7 @@ bool save_floor(PlayerType *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode
     saving_savefile = nullptr;
     safe_setuid_grab(player_ptr);
 
-    auto fd = fd_make(floor_savefile.data());
+    auto fd = fd_make(floor_savefile);
     safe_setuid_drop();
     bool is_save_successful = false;
     if (fd >= 0) {
index bb3b854..e54de00 100644 (file)
@@ -376,14 +376,14 @@ void fd_move(std::string_view from, std::string_view to)
 
 /*!
  * @brief OSごとの差異を吸収してファイルを作成する
- * @param file 作成先ファイルの相対パスまたは絶対パス
+ * @param path 作成先ファイルの相対パスまたは絶対パス
  * @param can_write_group グループに書き込みを許可するか否か
  */
-int fd_make(std::string_view file, bool can_write_group)
+int fd_make(const std::filesystem::path &path, bool can_write_group)
 {
     const auto permission = can_write_group ? 0644 : 0664;
-    const auto &path = path_parse(file);
-    return open(path.string().data(), O_CREAT | O_EXCL | O_WRONLY | O_BINARY, permission);
+    const auto &parsed_path = path_parse(path);
+    return open(parsed_path.string().data(), O_CREAT | O_EXCL | O_WRONLY | O_BINARY, permission);
 }
 
 /*
index 3ade8ba..3181523 100644 (file)
@@ -50,7 +50,7 @@ errr angband_fputs(FILE *fff, concptr buf, ulong n);
 errr angband_fclose(FILE *fff);
 void fd_kill(std::string_view file);
 void fd_move(std::string_view from, std::string_view to);
-int fd_make(std::string_view file, bool can_write_group = false);
+int fd_make(const std::filesystem::path &path, bool can_write_group = false);
 int fd_open(std::string_view file, int mode);
 errr fd_lock(int fd, int what);
 errr fd_seek(int fd, ulong n);