about summary refs log tree commit diff stats
path: root/src/os/os_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/os_linux.c')
-rw-r--r--src/os/os_linux.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/os/os_linux.c b/src/os/os_linux.c
index 570ce2ad..29d0a1d1 100644
--- a/src/os/os_linux.c
+++ b/src/os/os_linux.c
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <stdint.h>
 #include <sys/personality.h>
+#include <sys/stat.h>
 #include <dlfcn.h>
 #include <string.h>
 #include <stdarg.h>
@@ -207,4 +208,25 @@ void PrintfFtrace(int prefix, const char* fmt, ...)
 void* GetEnv(const char* name)
 {
     return getenv(name);
+}
+
+int FileExist(const char* filename, int flags)
+{
+    struct stat sb;
+    if (stat(filename, &sb) == -1)
+        return 0;
+    if (flags == -1)
+        return 1;
+    // check type of file? should be executable, or folder
+    if (flags & IS_FILE) {
+        if (!S_ISREG(sb.st_mode))
+            return 0;
+    } else if (!S_ISDIR(sb.st_mode))
+        return 0;
+
+    if (flags & IS_EXECUTABLE) {
+        if ((sb.st_mode & S_IXUSR) != S_IXUSR)
+            return 0; // nope
+    }
+    return 1;
 }
\ No newline at end of file