~martijnbraam/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH Megapixels] Use g_get_user_config_dir

Guido Günther
Details
Message ID
<7193b57b865e3f6510a2365b07e4bde9ecd74f79.1619452662.git.agx@sigxcpu.org>
DKIM signature
missing
Download raw message
Patch: +3 -25
Instead of opencoding rely on glib which handles XDG_CONFIG_HOME and
such. This also prevents xdg_config from leaking.
---
 camera_config.c    | 13 +------------
 process_pipeline.c | 15 ++-------------
 2 files changed, 3 insertions(+), 25 deletions(-)

diff --git a/camera_config.c b/camera_config.c
index 1e52d62..f8ecf05 100644
--- a/camera_config.c
+++ b/camera_config.c
@@ -3,7 +3,6 @@
#include "ini.h"
#include "config.h"
#include "matrix.h"
#include <wordexp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -21,18 +20,8 @@ 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
@@ -48,7 +37,7 @@ find_config(char *conffile)
		}

		// 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);
		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 64003a2..d18a86b 100644
--- a/process_pipeline.c
+++ b/process_pipeline.c
@@ -8,7 +8,6 @@
#include <tiffio.h>
#include <assert.h>
#include <math.h>
#include <wordexp.h>
#include <gtk/gtk.h>

#define TIFFTAG_FORWARDMATRIX1 50964
@@ -60,19 +59,9 @@ register_custom_tiff_tags(TIFF *tif)
static bool
find_processor(char *script)
{
	char *xdg_config_home;
	char filename[] = "postprocess.sh";
	wordexp_t exp_result;

	// 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
	// Check postprocess.sh in the current working directory
	sprintf(script, "%s", filename);
	if (access(script, F_OK) != -1) {
		sprintf(script, "./%s", filename);
@@ -81,7 +70,7 @@ find_processor(char *script)
	}

	// 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) {
		printf("Found postprocessor script at %s\n", script);
		return true;
-- 
2.30.1

[megapixels/patches] build success

builds.sr.ht
Details
Message ID
<CAXS33XMW4RG.3QPLXT6I0Z9OG@cirno2>
In-Reply-To
<7193b57b865e3f6510a2365b07e4bde9ecd74f79.1619452662.git.agx@sigxcpu.org> (view parent)
DKIM signature
missing
Download raw message
megapixels/patches: SUCCESS in 1m8s

[Use g_get_user_config_dir][0] from [Guido Günther][1]

[0]: https://lists.sr.ht/~martijnbraam/public-inbox/patches/22331
[1]: mailto:agx@sigxcpu.org

✓ #495953 SUCCESS megapixels/patches/alpine.yml https://builds.sr.ht/~martijnbraam/job/495953
✓ #495954 SUCCESS megapixels/patches/arch.yml   https://builds.sr.ht/~martijnbraam/job/495954
Details
Message ID
<26832457-3186-1234-0e47-269b6d9c8629@brixit.nl>
In-Reply-To
<7193b57b865e3f6510a2365b07e4bde9ecd74f79.1619452662.git.agx@sigxcpu.org> (view parent)
DKIM signature
missing
Download raw message
Thanks Guido, applied to master

On 4/26/21 5:57 PM, Guido Günther wrote:
> Instead of opencoding rely on glib which handles XDG_CONFIG_HOME and
> such. This also prevents xdg_config from leaking.
> ---
>   camera_config.c    | 13 +------------
>   process_pipeline.c | 15 ++-------------
>   2 files changed, 3 insertions(+), 25 deletions(-)
>
> diff --git a/camera_config.c b/camera_config.c
> index 1e52d62..f8ecf05 100644
> --- a/camera_config.c
> +++ b/camera_config.c
> @@ -3,7 +3,6 @@
>   #include "ini.h"
>   #include "config.h"
>   #include "matrix.h"
> -#include <wordexp.h>
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <string.h>
> @@ -21,18 +20,8 @@ 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
> @@ -48,7 +37,7 @@ find_config(char *conffile)
>   		}
>   
>   		// 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);
>   		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 64003a2..d18a86b 100644
> --- a/process_pipeline.c
> +++ b/process_pipeline.c
> @@ -8,7 +8,6 @@
>   #include <tiffio.h>
>   #include <assert.h>
>   #include <math.h>
> -#include <wordexp.h>
>   #include <gtk/gtk.h>
>   
>   #define TIFFTAG_FORWARDMATRIX1 50964
> @@ -60,19 +59,9 @@ register_custom_tiff_tags(TIFF *tif)
>   static bool
>   find_processor(char *script)
>   {
> -	char *xdg_config_home;
>   	char filename[] = "postprocess.sh";
> -	wordexp_t exp_result;
>   
> -	// 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
> +	// Check postprocess.sh in the current working directory
>   	sprintf(script, "%s", filename);
>   	if (access(script, F_OK) != -1) {
>   		sprintf(script, "./%s", filename);
> @@ -81,7 +70,7 @@ find_processor(char *script)
>   	}
>   
>   	// 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) {
>   		printf("Found postprocessor script at %s\n", script);
>   		return true;
Reply to thread Export thread (mbox)