Skip to content

Commit 93ece77

Browse files
committed
IO: added fs_writeable function
1 parent 308cdca commit 93ece77

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/modules/io/Filesystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern bool fs_mkdir(const char *path);
2727
extern bool fs_rmdir(const char *path);
2828
extern bool fs_unlink(const char *path);
2929
extern bool fs_exists(const char *path);
30+
extern bool fs_writeable(const char *path);
3031
extern bool fs_hidden(const char *path);
3132
extern bool fs_chdir(const char *path);
3233
extern core::String fs_realpath(const char *path);

src/modules/io/system/Null.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ bool fs_exists(const char *path) {
3333
return false;
3434
}
3535

36+
bool fs_writeable(const char *path) {
37+
return false;
38+
}
39+
3640
bool fs_chdir(const char *path) {
3741
return false;
3842
}

src/modules/io/system/Unix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ core::String fs_readlink(const char *path) {
281281
return buf;
282282
}
283283

284+
bool fs_writeable(const char *path) {
285+
return access(path, W_OK) == 0;
286+
}
287+
284288
static int fs_scandir_filter(const struct dirent *dent) {
285289
return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0;
286290
}

src/modules/io/system/Windows.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,22 @@ bool fs_hidden(const char *path) {
135135
bool fs_exists(const char *path) {
136136
WCHAR *wpath = io_UTF8ToStringW(path);
137137
priv::denormalizePath(wpath);
138-
const int ret = _waccess(wpath, 00);
138+
const int ret = _waccess(wpath, 0);
139139
SDL_free(wpath);
140140
if (ret != 0) {
141141
Log::debug("Failed to access %s: %s", path, strerror(errno));
142142
}
143143
return ret == 0;
144144
}
145145

146+
bool fs_writeable(const char *path) {
147+
WCHAR *wpath = io_UTF8ToStringW(path);
148+
priv::denormalizePath(wpath);
149+
const int ret = _waccess(wpath, 2);
150+
SDL_free(wpath);
151+
return ret == 0;
152+
}
153+
146154
bool fs_chdir(const char *path) {
147155
WCHAR *wpath = io_UTF8ToStringW(path);
148156
priv::denormalizePath(wpath);

0 commit comments

Comments
 (0)