2.9
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / ptsname.c
blobb68cd9c2ece20ed57602d4b43dd86554815ae004
1 /* ptsname -- return the name of a pty slave given an FD to the pty master
2 Copyright (C) 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <string.h>
22 #include <hurd.h>
23 #include <hurd/fd.h>
24 #include <hurd/term.h>
27 /* Return the pathname of the pseudo terminal slave associated with
28 the master FD is open on, or NULL on errors.
29 The returned storage is good until the next call to this function. */
30 char *
31 ptsname (int fd)
33 static char peername[1024]; /* XXX */
34 error_t err;
36 err = __ptsname_r (fd, peername, sizeof (peername));
37 if (err)
38 __set_errno (err);
40 return err ? NULL : peername;
44 /* Store at most BUFLEN characters of the pathname of the slave pseudo
45 terminal associated with the master FD is open on in BUF.
46 Return 0 on success, otherwise an error number. */
47 int
48 __ptsname_r (int fd, char *buf, size_t buflen)
50 char peername[1024]; /* XXX */
51 size_t len;
52 error_t err;
54 peername[0] = '\0';
55 if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername)))
56 return _hurd_fd_error (fd, err);
58 len = strlen (peername) + 1;
59 if (len > buflen)
60 return ERANGE;
62 memcpy (buf, peername, len);
63 return 0;
65 weak_alias (__ptsname_r, ptsname_r)