aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-05-18 20:29:16 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-05-18 20:29:16 -0700
commit5c3114c81477298e9eb78ed3a070752f8d24b8a5 (patch)
treed3f672824ed42c654561666e5ebe836ea6af1569 /sys
parent7ea7654db6e827038e38c3589c8d5b314db3fcb2 (diff)
feat: pulled out os specific code into its own file
Diffstat (limited to 'sys')
-rw-r--r--sys/libn/os.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/libn/os.c b/sys/libn/os.c
new file mode 100644
index 0000000..c9cc0ae
--- /dev/null
+++ b/sys/libn/os.c
@@ -0,0 +1,30 @@
+#include <u.h>
+#include <libn.h>
+
+int
+os·exists(byte *path, int flag)
+{
+ return access(path, flag) == 0;
+}
+
+int
+os·sep(void)
+{
+#if defined(UNIX) || defined(__linux__)
+ return '/';
+#elif defined(WIN32)
+ return '\\';
+#else
+ panicf("unrecognized operating system");
+ return '\0';
+#endif
+}
+
+byte*
+os·basename(byte *path)
+{
+ byte *sep;
+
+ sep = utf8·findrrune(path, os·sep());
+ return sep+1;
+}