diff --git a/src/modules/io/Filesystem.cpp b/src/modules/io/Filesystem.cpp index 1e2cffe67..3fc661a07 100644 --- a/src/modules/io/Filesystem.cpp +++ b/src/modules/io/Filesystem.cpp @@ -27,6 +27,7 @@ extern bool fs_mkdir(const char *path); extern bool fs_rmdir(const char *path); extern bool fs_unlink(const char *path); extern bool fs_exists(const char *path); +extern bool fs_writeable(const char *path); extern bool fs_hidden(const char *path); extern bool fs_chdir(const char *path); extern core::String fs_realpath(const char *path); diff --git a/src/modules/io/system/Null.cpp b/src/modules/io/system/Null.cpp index 0a52dd4dc..68cdac042 100644 --- a/src/modules/io/system/Null.cpp +++ b/src/modules/io/system/Null.cpp @@ -33,6 +33,10 @@ bool fs_exists(const char *path) { return false; } +bool fs_writeable(const char *path) { + return false; +} + bool fs_chdir(const char *path) { return false; } diff --git a/src/modules/io/system/Unix.cpp b/src/modules/io/system/Unix.cpp index 82dfa98ef..3b615977d 100644 --- a/src/modules/io/system/Unix.cpp +++ b/src/modules/io/system/Unix.cpp @@ -281,6 +281,10 @@ core::String fs_readlink(const char *path) { return buf; } +bool fs_writeable(const char *path) { + return access(path, W_OK) == 0; +} + static int fs_scandir_filter(const struct dirent *dent) { return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0; } diff --git a/src/modules/io/system/Windows.cpp b/src/modules/io/system/Windows.cpp index 19cf1c1be..628331cfe 100644 --- a/src/modules/io/system/Windows.cpp +++ b/src/modules/io/system/Windows.cpp @@ -135,7 +135,7 @@ bool fs_hidden(const char *path) { bool fs_exists(const char *path) { WCHAR *wpath = io_UTF8ToStringW(path); priv::denormalizePath(wpath); - const int ret = _waccess(wpath, 00); + const int ret = _waccess(wpath, 0); SDL_free(wpath); if (ret != 0) { Log::debug("Failed to access %s: %s", path, strerror(errno)); @@ -143,6 +143,14 @@ bool fs_exists(const char *path) { return ret == 0; } +bool fs_writeable(const char *path) { + WCHAR *wpath = io_UTF8ToStringW(path); + priv::denormalizePath(wpath); + const int ret = _waccess(wpath, 2); + SDL_free(wpath); + return ret == 0; +} + bool fs_chdir(const char *path) { WCHAR *wpath = io_UTF8ToStringW(path); priv::denormalizePath(wpath);