diff --git a/camera_config.c b/camera_config.c index f8ecf05..1e52d62 100644 --- a/camera_config.c +++ b/camera_config.c @@ -3,6 +3,7 @@ #include "ini.h" #include "config.h" #include "matrix.h" +#include #include #include #include @@ -20,8 +21,18 @@ static bool find_config(char *conffile) { char buf[512]; + char *xdg_config_home; + wordexp_t exp_result; FILE *fp; + // Resolve XDG stuff + if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL) { + xdg_config_home = "~/.config"; + } + wordexp(xdg_config_home, &exp_result, 0); + xdg_config_home = strdup(exp_result.we_wordv[0]); + wordfree(&exp_result); + if (access("/proc/device-tree/compatible", F_OK) != -1) { // Reads to compatible string of the current device tree, looks like: // pine64,pinephone-1.2\0allwinner,sun50i-a64\0 @@ -37,7 +48,7 @@ find_config(char *conffile) } // Check for a config file in XDG_CONFIG_HOME - sprintf(conffile, "%s/megapixels/config/%s.ini", g_get_user_config_dir (), + sprintf(conffile, "%s/megapixels/config/%s.ini", xdg_config_home, buf); if (access(conffile, F_OK) != -1) { printf("Found config file at %s\n", conffile); diff --git a/process_pipeline.c b/process_pipeline.c index d18a86b..64003a2 100644 --- a/process_pipeline.c +++ b/process_pipeline.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #define TIFFTAG_FORWARDMATRIX1 50964 @@ -59,9 +60,19 @@ register_custom_tiff_tags(TIFF *tif) static bool find_processor(char *script) { + char *xdg_config_home; char filename[] = "postprocess.sh"; + wordexp_t exp_result; - // Check postprocess.sh in the current working directory + // Resolve XDG stuff + if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL) { + xdg_config_home = "~/.config"; + } + wordexp(xdg_config_home, &exp_result, 0); + xdg_config_home = strdup(exp_result.we_wordv[0]); + wordfree(&exp_result); + + // Check postprocess.h in the current working directory sprintf(script, "%s", filename); if (access(script, F_OK) != -1) { sprintf(script, "./%s", filename); @@ -70,7 +81,7 @@ find_processor(char *script) } // Check for a script in XDG_CONFIG_HOME - sprintf(script, "%s/megapixels/%s", g_get_user_config_dir (), filename); + sprintf(script, "%s/megapixels/%s", xdg_config_home, filename); if (access(script, F_OK) != -1) { printf("Found postprocessor script at %s\n", script); return true;