1 /* posix-util.c - Utility functions for Posix
2 Copyright (C) 2001 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2004 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 /* These variables store the malloced name of alternative default
35 binaries. The are set only once by gpgme_set_global_flag. */
36 static char *default_gpg_name;
37 static char *default_gpgconf_name;
39 /* Set the default name for the gpg binary. This function may only be
40 called by gpgme_set_global_flag. Returns 0 on success. Leading
41 directories are removed from NAME. */
43 _gpgme_set_default_gpg_name (const char *name)
47 s = strrchr (name, '/');
51 if (!default_gpg_name)
52 default_gpg_name = strdup (name);
53 return !default_gpg_name;
56 /* Set the default name for the gpgconf binary. This function may
57 only be called by gpgme_set_global_flag. Returns 0 on success.
58 Leading directories are removed from NAME. */
60 _gpgme_set_default_gpgconf_name (const char *name)
64 s = strrchr (name, '/');
68 if (!default_gpgconf_name)
69 default_gpgconf_name = strdup (name);
70 return !default_gpgconf_name;
74 /* Find an executable program PGM along the envvar PATH. */
76 walk_path (const char *pgm)
78 const char *orig_path, *path, *s;
81 #ifdef FIXED_SEARCH_PATH
82 orig_path = FIXED_SEARCH_PATH;
84 orig_path = getenv ("PATH");
86 orig_path = "/bin:/usr/bin";
89 fname = malloc (strlen (orig_path) + 1 + strlen (pgm) + 1);
96 for (s=path, p=fname; *s && *s != ':'; s++, p++)
98 if (p != fname && p[-1] != '/')
101 if (!access (fname, X_OK))
108 _gpgme_debug (DEBUG_ENGINE, "gpgme-walk_path: '%s' not found in '%s'",
116 /* Return the full file name of the GPG binary. This function is used
117 if gpgconf was not found and thus it can be assumed that gpg2 is
118 not installed. This function is only called by get_gpgconf_item
119 and may not be called concurrently. */
121 _gpgme_get_gpg_path (void)
123 return walk_path (default_gpg_name? default_gpg_name : "gpg");
127 /* This function is only called by get_gpgconf_item and may not be
128 called concurrently. */
130 _gpgme_get_gpgconf_path (void)
132 return walk_path (default_gpgconf_name? default_gpgconf_name : "gpgconf");
137 _gpgme_get_conf_int (const char *key, int *value)
143 _gpgme_allow_set_foreground_window (pid_t pid)