summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-11 15:35:40 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-11 15:35:40 +1100
commit1c6ec0b7b8e437a003137428636149132d998357 (patch)
treeada9de786fa292cb622e66d9491834179307f392 /src/platform
parent8019f49a4b0d657f882c148ae6582da78a7d2262 (diff)
added a path_parent function to get path of a file
Now we can load .mtl files without hardcoding the full path from top-level like before. that was a hack!
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/path.c15
-rw-r--r--src/platform/path.h16
2 files changed, 31 insertions, 0 deletions
diff --git a/src/platform/path.c b/src/platform/path.c
new file mode 100644
index 0000000..e67102b
--- /dev/null
+++ b/src/platform/path.c
@@ -0,0 +1,15 @@
+#include "path.h"
+
+#include <libgen.h>
+#include <string.h>
+#include "str.h"
+
+#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
+path_opt path_parent(const char* path) {
+ char* path_dirname = dirname(path);
+ return (path_opt){ .path = str8_cstr_view(path_dirname), .has_value = true };
+}
+#endif
+#ifdef CEL_PLATFORM_WINDOWS
+// TODO: path_opt path_parent(const char* path)
+#endif \ No newline at end of file
diff --git a/src/platform/path.h b/src/platform/path.h
new file mode 100644
index 0000000..0ec6993
--- /dev/null
+++ b/src/platform/path.h
@@ -0,0 +1,16 @@
+/**
+ * @file path.h
+ * @brief
+ * @date 2024-03-11
+ * @copyright Copyright (c) 2024
+ */
+#pragma once
+
+#include "str.h"
+
+typedef struct path_opt {
+ str8 path;
+ bool has_value;
+} path_opt;
+
+path_opt path_parent(const char* path); // TODO: convert to using str8 \ No newline at end of file