Use gpgme interface for error handling to avoid linking with gpg-error.
[gpgme.git] / src / engine-gpgconf.c
index d3c47a755b1ee1273dee9c570af6591ce5757b1c..6807dce9cf95188bb64de149d153d7ac70559cd7 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
 #include <assert.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 #include <fcntl.h> /* FIXME */
 #include <errno.h>
 
@@ -533,7 +537,7 @@ gpgconf_conf_load (void *engine, gpgme_conf_comp_t *comp_p)
 \f
 gpgme_error_t
 _gpgme_conf_arg_new (gpgme_conf_arg_t *arg_p,
-                    gpgme_conf_type_t type, void *value)
+                    gpgme_conf_type_t type, const void *value)
 {
   gpgme_conf_arg_t arg;
 
@@ -614,16 +618,19 @@ _gpgme_conf_arg_release (gpgme_conf_arg_t arg, gpgme_conf_type_t type)
 gpgme_error_t
 _gpgme_conf_opt_change (gpgme_conf_opt_t opt, int reset, gpgme_conf_arg_t arg)
 {
-  if (opt->new_value)
-    release_arg (opt->new_value, opt->alt_type);
-
   if (reset)
     {
+      if (opt->new_value)
+       release_arg (opt->new_value, opt->alt_type);
       opt->new_value = NULL;
       opt->change_value = 0;
     }
   else
     {
+      /* Support self-assignment, for example for adding an item to an
+        existing list.  */
+      if (opt->new_value && arg != opt->new_value)
+       release_arg (opt->new_value, opt->alt_type);
       opt->new_value = arg;
       opt->change_value = 1;
     }
@@ -651,7 +658,6 @@ gpgconf_write (void *engine, char *arg1, char *arg2, gpgme_data_t conf)
 
   /* _gpgme_engine_new guarantees that this is not NULL.  */
   argv[0] = gpgconf->file_name;
-  argv[0] = "/nowhere/path-needs-to-be-fixed/gpgconf";
 
   if (_gpgme_io_pipe (rp, 0) < 0)
     return gpg_error_from_syserror ();