Use g_get_user_config_dir
Instead of opencoding rely on glib which handles XDG_CONFIG_HOME and such. This also prevents xdg_config from leaking.
This commit is contained in:
parent
59dde6bb74
commit
0046986e3e
|
@ -3,7 +3,6 @@
|
||||||
#include "ini.h"
|
#include "ini.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include <wordexp.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -21,18 +20,8 @@ static bool
|
||||||
find_config(char *conffile)
|
find_config(char *conffile)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
char *xdg_config_home;
|
|
||||||
wordexp_t exp_result;
|
|
||||||
FILE *fp;
|
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) {
|
if (access("/proc/device-tree/compatible", F_OK) != -1) {
|
||||||
// Reads to compatible string of the current device tree, looks like:
|
// Reads to compatible string of the current device tree, looks like:
|
||||||
// pine64,pinephone-1.2\0allwinner,sun50i-a64\0
|
// pine64,pinephone-1.2\0allwinner,sun50i-a64\0
|
||||||
|
@ -48,7 +37,7 @@ find_config(char *conffile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a config file in XDG_CONFIG_HOME
|
// Check for a config file in XDG_CONFIG_HOME
|
||||||
sprintf(conffile, "%s/megapixels/config/%s.ini", xdg_config_home,
|
sprintf(conffile, "%s/megapixels/config/%s.ini", g_get_user_config_dir (),
|
||||||
buf);
|
buf);
|
||||||
if (access(conffile, F_OK) != -1) {
|
if (access(conffile, F_OK) != -1) {
|
||||||
printf("Found config file at %s\n", conffile);
|
printf("Found config file at %s\n", conffile);
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <tiffio.h>
|
#include <tiffio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <wordexp.h>
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "gl_util.h"
|
#include "gl_util.h"
|
||||||
|
@ -70,20 +69,10 @@ register_custom_tiff_tags(TIFF *tif)
|
||||||
static bool
|
static bool
|
||||||
find_processor(char *script)
|
find_processor(char *script)
|
||||||
{
|
{
|
||||||
char *xdg_config_home;
|
|
||||||
char filename[] = "postprocess.sh";
|
char filename[] = "postprocess.sh";
|
||||||
wordexp_t exp_result;
|
|
||||||
|
|
||||||
// Resolve XDG stuff
|
// Check postprocess.sh in the current working directory
|
||||||
if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL) {
|
sprintf(script, "./data/%s", filename);
|
||||||
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, "data/%s", filename);
|
|
||||||
if (access(script, F_OK) != -1) {
|
if (access(script, F_OK) != -1) {
|
||||||
sprintf(script, "./data/%s", filename);
|
sprintf(script, "./data/%s", filename);
|
||||||
printf("Found postprocessor script at %s\n", script);
|
printf("Found postprocessor script at %s\n", script);
|
||||||
|
@ -91,7 +80,7 @@ find_processor(char *script)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a script in XDG_CONFIG_HOME
|
// Check for a script in XDG_CONFIG_HOME
|
||||||
sprintf(script, "%s/megapixels/%s", xdg_config_home, filename);
|
sprintf(script, "%s/megapixels/%s", g_get_user_config_dir(), filename);
|
||||||
if (access(script, F_OK) != -1) {
|
if (access(script, F_OK) != -1) {
|
||||||
printf("Found postprocessor script at %s\n", script);
|
printf("Found postprocessor script at %s\n", script);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue