gpgconf: Fix some warnings.

* tests/gpg/t-gpgconf.c (main): Fix warnings.
* src/engine-gpgconf.c (struct gpgconf_config_dir_s): New struct.
(gpgconf_config_dir_cb, gpgconf_conf_dir) Use it to fix warning.

Signed-off-by: Marcus Brinkmann <mb@g10code.com>
This commit is contained in:
Marcus Brinkmann 2017-08-16 01:50:00 +02:00
parent 97a1abe72e
commit 3244d4daff
2 changed files with 32 additions and 23 deletions

View File

@ -986,20 +986,25 @@ gpgconf_conf_save (void *engine, gpgme_conf_comp_t comp)
}
struct gpgconf_config_dir_s
{
const char *what;
char *result;
};
static gpgme_error_t
gpgconf_config_dir_cb (void *hook, char *line)
{
/* This is an input- and output-parameter. */
char **str_p = (char **) hook;
char *what = *str_p;
int len = strlen(what);
struct gpgconf_config_dir_s *data = (char **) hook;
int len = strlen(data->what);
if (!strncmp(line, what, len) && line[len] == ':')
if (!strncmp(line, data->what, len) && line[len] == ':')
{
char *result = strdup(&line[len + 1]);
if (!result)
return gpg_error_from_syserror ();
*str_p = result;
data->result = result;
return gpg_error(GPG_ERR_USER_1);
}
return 0;
@ -1010,15 +1015,16 @@ static gpgme_error_t
gpgconf_conf_dir (void *engine, const char *what, char **result)
{
gpgme_error_t err;
char *res = what;
struct gpgconf_config_dir_s data;
*result = NULL;
data.what = what;
data.result = NULL;
err = gpgconf_read (engine, "--list-dirs", NULL,
gpgconf_config_dir_cb, &res);
gpgconf_config_dir_cb, &data);
if (gpg_err_code (err) == GPG_ERR_USER_1)
{
/* This signals to use that a result was found. */
*result = res;
*result = data.result;
return 0;
}

View File

@ -263,22 +263,25 @@ main (void)
err = gpgme_new (&ctx);
fail_if_err (err);
/* Let's check getting the agent-socket directory for different homedirs. */
char *result1 = NULL;
err = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_GPGCONF, NULL, "/tmp/foo");
fail_if_err (err);
err = gpgme_op_conf_dir (ctx, "agent-socket", &result1);
fail_if_err (err);
{
/* Let's check getting the agent-socket directory for different homedirs. */
char *result1 = NULL;
char *result2 = NULL;
err = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_GPGCONF, NULL, "/tmp/foo");
fail_if_err (err);
err = gpgme_op_conf_dir (ctx, "agent-socket", &result1);
fail_if_err (err);
char *result2 = NULL;
err = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_GPGCONF, NULL, NULL);
fail_if_err (err);
err = gpgme_op_conf_dir (ctx, "agent-socket", &result2);
fail_if_err (err);
/* They have to be different. */
test (strcmp(result1, result2));
err = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_GPGCONF, NULL, NULL);
fail_if_err (err);
err = gpgme_op_conf_dir (ctx, "agent-socket", &result2);
fail_if_err (err);
/* They have to be different. */
test (strcmp(result1, result2));
gpgme_free (result1);
gpgme_free (result2);
}
err = gpgme_op_conf_load (ctx, &conf);
fail_if_err (err);