Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / mach / hurd / ptsname.c
bloba35bbd430ff341abfee067bcaf1ab1181c8753cf
1 /* ptsname -- return the name of a pty slave given an FD to the pty master
2 Copyright (C) 1999-2015 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <string.h>
21 #include <hurd.h>
22 #include <hurd/fd.h>
23 #include <hurd/term.h>
26 /* Return the pathname of the pseudo terminal slave associated with
27 the master FD is open on, or NULL on errors.
28 The returned storage is good until the next call to this function. */
29 char *
30 ptsname (int fd)
32 static string_t peername;
33 error_t err;
35 err = __ptsname_r (fd, peername, sizeof (peername));
37 return err ? NULL : peername;
41 /* Store at most BUFLEN characters of the pathname of the slave pseudo
42 terminal associated with the master FD is open on in BUF.
43 Return 0 on success, otherwise an error number. */
44 int
45 __ptsname_r (int fd, char *buf, size_t buflen)
47 string_t peername;
48 size_t len;
49 error_t err;
51 if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername)))
52 return __hurd_dfail (fd, err), errno;
54 len = __strnlen (peername, sizeof peername - 1) + 1;
55 if (len > buflen)
57 errno = ERANGE;
58 return ERANGE;
61 memcpy (buf, peername, len);
62 return 0;
64 weak_alias (__ptsname_r, ptsname_r)