-#pragma once
+#pragma once
#include "system/angband.h"
+#include <filesystem>
+#include <string_view>
/* Force definitions -- see fd_seek() */
#ifndef SEEK_SET
#ifdef SET_UID
extern void user_name(char *buf, int id);
#ifndef HAVE_USLEEP
-extern int usleep(huge usecs);
+extern int usleep(ulong usecs);
#endif
#endif
-errr path_parse(char *buf, int max, concptr file);
-errr path_build(char *buf, int max, concptr path, concptr file);
-FILE *angband_fopen(concptr file, concptr mode);
+#define FILE_READ_BUFF_SIZE 65535
+
+enum class FileOpenMode {
+ READ,
+ WRITE,
+ APPEND,
+};
+
+// Specifies what king of thing a file is, when writing. See file_open().
+enum class FileOpenType {
+ TEXT,
+ SAVE,
+ RAW,
+ HTML,
+};
+
+extern void (*file_open_hook)(const std::filesystem::path &path, const FileOpenType ftype);
+
+std::filesystem::path path_parse(const std::filesystem::path &path);
+std::filesystem::path path_build(const std::filesystem::path &path, std::string_view file);
+FILE *angband_fopen(const std::filesystem::path &path, const FileOpenMode mode, const bool is_binary = false, const FileOpenType ftype = FileOpenType::TEXT);
FILE *angband_fopen_temp(char *buf, int max);
-errr angband_fgets(FILE *fff, char *buf, huge n);
-errr angband_fputs(FILE *fff, concptr buf, huge n);
+errr angband_fgets(FILE *fff, char *buf, ulong n);
+errr angband_fputs(FILE *fff, concptr buf, ulong n);
errr angband_fclose(FILE *fff);
-errr fd_kill(concptr file);
-errr fd_move(concptr file, concptr what);
-errr fd_copy(concptr file, concptr what);
-int fd_make(concptr file, BIT_FLAGS mode);
-int fd_open(concptr file, int flags);
+void fd_kill(const std::filesystem::path &path);
+void fd_move(const std::filesystem::path &path_from, const std::filesystem::path &path_to);
+int fd_make(const std::filesystem::path &path, bool can_write_group = false);
+int fd_open(const std::filesystem::path &path, int mode);
errr fd_lock(int fd, int what);
-errr fd_seek(int fd, huge n);
-errr fd_chop(int fd, huge n);
-errr fd_read(int fd, char *buf, huge n);
-errr fd_write(int fd, concptr buf, huge n);
+errr fd_seek(int fd, ulong n);
+errr fd_read(int fd, char *buf, ulong n);
+errr fd_write(int fd, concptr buf, ulong n);
errr fd_close(int fd);