]>
Commit | Line | Data |
---|---|---|
0702b5f4 | 1 | /* ptsname -- return the name of a pty slave given an FD to the pty master |
f7a9f785 | 2 | Copyright (C) 1999-2016 Free Software Foundation, Inc. |
0702b5f4 RM |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
0702b5f4 RM |
9 | |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
0702b5f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
0702b5f4 RM |
18 | |
19 | #include <errno.h> | |
20 | #include <string.h> | |
21 | #include <hurd.h> | |
22 | #include <hurd/fd.h> | |
23 | #include <hurd/term.h> | |
24 | ||
25 | ||
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) | |
31 | { | |
986cab95 | 32 | static string_t peername; |
0702b5f4 RM |
33 | error_t err; |
34 | ||
35 | err = __ptsname_r (fd, peername, sizeof (peername)); | |
0702b5f4 RM |
36 | |
37 | return err ? NULL : peername; | |
38 | } | |
39 | ||
40 | ||
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) | |
46 | { | |
986cab95 | 47 | string_t peername; |
0702b5f4 RM |
48 | size_t len; |
49 | error_t err; | |
50 | ||
0702b5f4 | 51 | if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername))) |
986cab95 | 52 | return __hurd_dfail (fd, err), errno; |
0702b5f4 | 53 | |
986cab95 | 54 | len = __strnlen (peername, sizeof peername - 1) + 1; |
0702b5f4 | 55 | if (len > buflen) |
986cab95 PT |
56 | { |
57 | errno = ERANGE; | |
58 | return ERANGE; | |
59 | } | |
0702b5f4 RM |
60 | |
61 | memcpy (buf, peername, len); | |
62 | return 0; | |
63 | } | |
64 | weak_alias (__ptsname_r, ptsname_r) |