Updated the german translation
[gnupg.git] / sm / misc.c
blob628b321ebe02efdc8b570bd813ce3a2a77df0c5d
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/>.
20 #include <config.h>
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <unistd.h>
27 #ifdef HAVE_LOCALE_H
28 #include <locale.h>
29 #endif
31 #include "gpgsm.h"
32 #include "i18n.h"
33 #include "setenv.h"
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
37 protect-tool. */
38 void
39 setup_pinentry_env (void)
41 #ifndef HAVE_W32_SYSTEM
42 char *lc;
43 const char *name, *value;
44 int iterator;
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");
51 if (value)
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"));
57 lc = ttyname (0);
58 if (!lc)
59 lc = "/dev/tty";
60 setenv ("GPG_TTY", lc, 1);
63 if (opt.lc_ctype)
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);
68 #endif
70 if (opt.lc_messages)
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);
75 #endif
77 iterator = 0;
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);
83 if (value)
84 setenv (name, value, 1);
87 #endif /*!HAVE_W32_SYSTEM*/