1 /* misc.c - Miscellaneous fucntions
2 * Copyright (C) 2004, 2009 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
35 /* Setup the environment so that the pinentry is able to get all
36 required information. This is used prior to an exec of the
39 setup_pinentry_env (void)
41 #ifndef HAVE_W32_SYSTEM
43 const char *name
, *value
;
46 /* Try to make sure that GPG_TTY has been set. This is needed if we
47 call for example the protect-tools with redirected stdin and thus
48 it won't be able to ge a default by itself. Try to do it here
49 but print a warning. */
50 value
= session_env_getenv (opt
.session_env
, "GPG_TTY");
52 setenv ("GPG_TTY", value
, 1);
53 else if (!(lc
=getenv ("GPG_TTY")) || !*lc
)
55 log_error (_("GPG_TTY has not been set - "
56 "using maybe bogus default\n"));
60 setenv ("GPG_TTY", lc
, 1);
64 setenv ("LC_CTYPE", opt
.lc_ctype
, 1);
65 #if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
66 else if ( (lc
= setlocale (LC_CTYPE
, "")) )
67 setenv ("LC_CTYPE", lc
, 1);
71 setenv ("LC_MESSAGES", opt
.lc_messages
, 1);
72 #if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
73 else if ( (lc
= setlocale (LC_MESSAGES
, "")) )
74 setenv ("LC_MESSAGES", lc
, 1);
78 while ((name
= session_env_list_stdenvnames (&iterator
, NULL
)))
80 if (!strcmp (name
, "GPG_TTY"))
81 continue; /* Already set. */
82 value
= session_env_getenv (opt
.session_env
, name
);
84 setenv (name
, value
, 1);
87 #endif /*!HAVE_W32_SYSTEM*/