aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-08-15 01:53:40 +0200
committerkdx <kikoodx@paranoici.org>2023-08-15 01:53:40 +0200
commit48e261f6f11b7b0f239b122d0c5a89799a6eae2f (patch)
treed171366a2b4e80ecb68f6c5cc03385a644c3ce44
parent7182ece87bace03ef6b4a268b961ae51ee44318c (diff)
downloadtzr-48e261f6f11b7b0f239b122d0c5a89799a6eae2f.tar.gz
allow to set custom basepath
-rw-r--r--headers/TZR.h1
-rw-r--r--headers/TZR_types.h1
-rw-r--r--sources/TZR_Init.c14
3 files changed, 11 insertions, 5 deletions
diff --git a/headers/TZR.h b/headers/TZR.h
index 3144cca..7cefb64 100644
--- a/headers/TZR.h
+++ b/headers/TZR.h
@@ -20,6 +20,7 @@
.scale_linear=false, \
.show_cursor=false, \
.mixer=TZR_MIXER_ON, \
+ .basepath=NULL, \
.title="TZR", \
._=0, __VA_ARGS__ }; \
_TZR_Init(&____arg); })
diff --git a/headers/TZR_types.h b/headers/TZR_types.h
index 5af1f17..58aee45 100644
--- a/headers/TZR_types.h
+++ b/headers/TZR_types.h
@@ -60,6 +60,7 @@ struct TZR_Config {
bool scale_linear;
bool show_cursor;
unsigned int mixer;
+ const char *basepath;
const char *title;
};
diff --git a/sources/TZR_Init.c b/sources/TZR_Init.c
index a508892..4d306a7 100644
--- a/sources/TZR_Init.c
+++ b/sources/TZR_Init.c
@@ -28,11 +28,15 @@ _TZR_Init(const TZR_Config *config)
___tzr_config.mixer = TZR_MIXER_OFF;
}
- char *const basepath = SDL_GetBasePath();
- if (basepath == NULL)
- return _sdl_error();
- const int chdir_rv = chdir(basepath);
- SDL_free(basepath);
+ int chdir_rv;
+ if (___tzr_config.basepath == NULL) {
+ char *const basepath = SDL_GetBasePath();
+ if (basepath == NULL)
+ return _sdl_error();
+ chdir_rv = chdir(basepath);
+ SDL_free(basepath);
+ } else
+ chdir_rv = chdir(___tzr_config.basepath);
if (chdir_rv < 0)
return perror("TZR_Init"), -1;