~ubuntu-branches/ubuntu/dapper/gnupg2/dapper

« back to all changes in this revision

Viewing changes to sm/misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* misc.c - Miscellaneous fucntions
 
2
 *      Copyright (C) 2004 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
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 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
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.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
#include <errno.h>
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
#include <ctype.h>
 
27
#include <unistd.h>
 
28
#ifdef HAVE_LOCALE_H
 
29
#include <locale.h>
 
30
#endif
 
31
 
 
32
#include "gpgsm.h"
 
33
#include "i18n.h"
 
34
 
 
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)
 
40
{
 
41
#ifndef HAVE_W32_SYSTEM
 
42
  char *lc;
 
43
 
 
44
  if (opt.display)
 
45
    setenv ("DISPLAY", opt.display, 1);
 
46
 
 
47
  /* Try to make sure that GPG_TTY has been set.  This is needed if we
 
48
     call for example the protect-tools with redirected stdin and thus
 
49
     it won't be able to ge a default by itself.  Try to do it here
 
50
     but print a warning.  */
 
51
  if (opt.ttyname)
 
52
    setenv ("GPG_TTY", opt.ttyname, 1);
 
53
  else if (!(lc=getenv ("GPG_TTY")) || !*lc)
 
54
    {
 
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);
 
61
    }
 
62
 
 
63
  if (opt.ttytype)
 
64
    setenv ("TERM", opt.ttytype, 1);
 
65
 
 
66
  if (opt.lc_ctype)
 
67
    setenv ("LC_CTYPE", opt.lc_ctype, 1);
 
68
#if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
 
69
  else if ( (lc = setlocale (LC_CTYPE, "")) )
 
70
    setenv ("LC_CTYPE", lc, 1);
 
71
#endif
 
72
 
 
73
  if (opt.lc_messages)
 
74
    setenv ("LC_MESSAGES", opt.lc_messages, 1);
 
75
#if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
 
76
  else if ( (lc = setlocale (LC_MESSAGES, "")) )
 
77
    setenv ("LC_MESSAGES", lc, 1);
 
78
#endif
 
79
#endif /*!HAVE_W32_SYSTEM*/
 
80
}
 
81