summaryrefslogtreecommitdiffhomepage
path: root/compat/os-file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/os-file.cpp')
-rw-r--r--compat/os-file.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/compat/os-file.cpp b/compat/os-file.cpp
new file mode 100644
index 00000000..0d8f95c2
--- /dev/null
+++ b/compat/os-file.cpp
@@ -0,0 +1,27 @@
+#include "os-file.hpp"
+#include "assert.hpp"
+#include <cerrno>
+#include <cr/StringView.h>
+
+#ifdef _WIN32
+#include <io.h>
+#define fm_os_access _access
+#else
+#include <unistd.h>
+#define fm_os_access access
+#endif
+
+namespace floormat::fs {
+
+bool file_exists(StringView name)
+{
+ fm_assert(name.flags() & StringViewFlag::NullTerminated);
+ fm_debug_assert(!name.find('\0'));
+ if (!fm_os_access(name.data(), F_OK))
+ return true;
+ int error = errno;
+ // just let it die if the file exists but can't be accessed
+ return error != ENOENT;
+}
+
+} // namespace floormat::fs