Skip to content

Commit

Permalink
IO: added fs_writeable function
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Sep 15, 2024
1 parent 308cdca commit 93ece77
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/modules/io/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/io/system/Null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/modules/io/system/Unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 9 additions & 1 deletion src/modules/io/system/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,22 @@ 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));
}
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);
Expand Down

0 comments on commit 93ece77

Please sign in to comment.