~ubuntu-branches/ubuntu/lucid/gpgme1.0/lucid

« back to all changes in this revision

Viewing changes to src/ttyname_r.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman, Bhavani Shankar, Scott Kitterman
  • Date: 2008-12-31 02:39:33 UTC
  • mfrom: (1.1.6 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081231023933-zi5r2w9vf7fdz0x9
Tags: 1.1.8-1ubuntu1
[ Bhavani Shankar ]
* Merge from debian unstable, remaining changes: LP: #311666
  - debian/rules: enable tests

[ Scott Kitterman ]
* Re-enable testsuite on armel since it's no longer a first build 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ttyname_r.c - A ttyname_r() replacement.
 
2
   Copyright (C) 2003, 2004 g10 Code GmbH
 
3
 
 
4
   This file is part of GPGME.
 
5
 
 
6
   GPGME is free software; you can redistribute it and/or modify it
 
7
   under the terms of the GNU Lesser General Public License as
 
8
   published by the Free Software Foundation; either version 2.1 of
 
9
   the License, or (at your option) any later version.
 
10
   
 
11
   GPGME is distributed in the hope that it will be useful, but
 
12
   WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Lesser General Public License for more details.
 
15
   
 
16
   You should have received a copy of the GNU Lesser General Public
 
17
   License along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
   02111-1307, USA.  */
 
20
 
 
21
#if HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
#include <stdlib.h>
 
25
#include <errno.h>
 
26
#include <string.h>
 
27
#include <unistd.h>
 
28
 
 
29
 
 
30
#warning ttyname is not thread-safe, and ttyname_r is missing
 
31
 
 
32
int
 
33
ttyname_r (int fd, char *buf, size_t buflen)
 
34
{
 
35
  char *tty;
 
36
 
 
37
#if HAVE_W32_SYSTEM
 
38
  /* We use this default one for now.  AFAICS we only need it to be
 
39
     passed to gpg and in turn to pinentry.  Providing a replacement
 
40
     is needed because elsewhere we bail out on error.  If we
 
41
     eventually implement a pinentry for Windows it is uinlikely that
 
42
     we need a real tty at all.  */
 
43
  tty = "/dev/tty"; 
 
44
#else
 
45
  tty = ttyname (fd);
 
46
  if (!tty)
 
47
    return errno;
 
48
#endif
 
49
  
 
50
  strncpy (buf, tty, buflen);
 
51
  buf[buflen - 1] = '\0';
 
52
  return (strlen (tty) >= buflen) ? ERANGE : 0;
 
53
}