summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-10-28 18:20:24 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-10-28 18:20:24 +0200
commit1ed4742c8938c67998c829dec90d82221f98cb94 (patch)
tree1043e0f3e3c6d508aeb167ba81959b4d23ed7cd8 /source
parenta1a11b0092fcc1b687717929b03c4288fc473c16 (diff)
downloadkit-1ed4742c8938c67998c829dec90d82221f98cb94.zip
win32: Fix temp path
Diffstat (limited to 'source')
-rw-r--r--source/kit/file.c14
-rw-r--r--source/kit/file.h21
-rw-r--r--source/tests/file.test.c6
3 files changed, 20 insertions, 21 deletions
diff --git a/source/kit/file.c b/source/kit/file.c
index 07e18f4..10f4857 100644
--- a/source/kit/file.c
+++ b/source/kit/file.c
@@ -36,9 +36,9 @@ static i32 is_delim(char c) {
return c == '/' || c == '\\';
}
-static kit_str_builder_t kit_get_env_(char *name,
- kit_allocator_t *alloc) {
- char *val = getenv(name);
+kit_str_builder_t kit_get_env(kit_str_t name,
+ kit_allocator_t *alloc) {
+ char *val = getenv(BS(name));
i64 size = val != NULL ? (i64) strlen(val) : 0;
str_builder_t result;
@@ -138,7 +138,7 @@ kit_str_builder_t kit_path_join(kit_str_t left, kit_str_t right,
}
kit_str_builder_t kit_path_user(kit_allocator_t *alloc) {
- kit_str_builder_t user = kit_get_env_(KIT_ENV_HOME, alloc);
+ kit_str_builder_t user = kit_get_env(SZ(KIT_ENV_HOME), alloc);
if (user.size == 0) {
DA_RESIZE(user, 1);
if (user.size == 1)
@@ -150,7 +150,7 @@ kit_str_builder_t kit_path_user(kit_allocator_t *alloc) {
kit_str_builder_t kit_path_cache(kit_allocator_t *alloc) {
kit_str_builder_t cache, user;
- cache = kit_get_env_("XDG_CACHE_HOME", alloc);
+ cache = kit_get_env(SZ("XDG_CACHE_HOME"), alloc);
if (cache.size != 0)
return cache;
DA_DESTROY(cache);
@@ -178,13 +178,13 @@ kit_str_builder_t kit_path_cache(kit_allocator_t *alloc) {
kit_str_builder_t kit_path_data(kit_allocator_t *alloc) {
kit_str_builder_t data, user;
- data = kit_get_env_("XDG_DATA_HOME", alloc);
+ data = kit_get_env(SZ("XDG_DATA_HOME"), alloc);
if (data.size != 0)
return data;
DA_DESTROY(data);
#if defined(_WIN32) && !defined(__CYGWIN__)
- data = kit_get_env_("LOCALAPPDATA", alloc);
+ data = kit_get_env(SZ("LOCALAPPDATA"), alloc);
if (data.size != 0)
return data;
DA_DESTROY(data);
diff --git a/source/kit/file.h b/source/kit/file.h
index 7eddfb8..b9988f1 100644
--- a/source/kit/file.h
+++ b/source/kit/file.h
@@ -11,6 +11,16 @@
extern "C" {
#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+# define KIT_PATH_DELIM_C '\\'
+# define KIT_PATH_DELIM "\\"
+# define KIT_ENV_HOME "USERPROFILE"
+#else
+# define KIT_PATH_DELIM_C '/'
+# define KIT_PATH_DELIM "/"
+# define KIT_ENV_HOME "HOME"
+#endif
+
typedef enum {
KIT_PATH_NONE,
KIT_PATH_FILE,
@@ -44,15 +54,7 @@ typedef struct {
#endif
} kit_mapped_file_t;
-#if defined(_WIN32) && !defined(__CYGWIN__)
-# define KIT_PATH_DELIM_C '\\'
-# define KIT_PATH_DELIM "\\"
-# define KIT_ENV_HOME "USERPROFILE"
-#else
-# define KIT_PATH_DELIM_C '/'
-# define KIT_PATH_DELIM "/"
-# define KIT_ENV_HOME "HOME"
-#endif
+kit_str_builder_t kit_get_env(kit_str_t name, kit_allocator_t *alloc);
kit_str_builder_t kit_path_norm(kit_str_t path,
kit_allocator_t *alloc);
@@ -104,6 +106,7 @@ kit_status_t kit_file_unmap(kit_mapped_file_t *mf);
# define path_list_t kit_path_list_t
# define mapped_file_t kit_mapped_file_t
+# define get_env kit_get_env
# define path_norm kit_path_norm
# define path_join kit_path_join
# define path_user kit_path_user
diff --git a/source/tests/file.test.c b/source/tests/file.test.c
index 6fde8fa..646d0ef 100644
--- a/source/tests/file.test.c
+++ b/source/tests/file.test.c
@@ -14,9 +14,7 @@ TEST("path cache") {
str_builder_t expected =
#if defined(_WIN32) && !defined(__CYGWIN__)
- path_join(WRAP_STR(user),
- SZ("AppData" PATH_DELIM "Local" PATH_DELIM "Temp"),
- NULL);
+ get_env(SZ("TEMP"), NULL);
#elif defined(__APPLE__)
path_join(WRAP_STR(user), SZ("Library" PATH_DELIM "Caches"),
NULL);
@@ -24,8 +22,6 @@ TEST("path cache") {
path_join(WRAP_STR(user), SZ(".cache"), NULL);
#endif
- printf("cache: %s \ngot: %s \n", BS(cache), BS(expected));
-
REQUIRE(AR_EQUAL(cache, expected));
DA_DESTROY(user);