]>
Commit | Line | Data |
---|---|---|
0702b5f4 | 1 | /* ptsname -- return the name of a pty slave given an FD to the pty master |
04277e02 | 2 | Copyright (C) 1999-2019 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> | |
dd1efd8c | 21 | #include <sys/stat.h> |
0702b5f4 RM |
22 | #include <hurd.h> |
23 | #include <hurd/fd.h> | |
24 | #include <hurd/term.h> | |
25 | ||
26 | ||
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) | |
32 | { | |
986cab95 | 33 | static string_t peername; |
0702b5f4 RM |
34 | error_t err; |
35 | ||
36 | err = __ptsname_r (fd, peername, sizeof (peername)); | |
0702b5f4 RM |
37 | |
38 | return err ? NULL : peername; | |
39 | } | |
40 | ||
41 | ||
dd1efd8c | 42 | /* We don't need STP, but fill it for conformity with the Linux version... */ |
0702b5f4 | 43 | int |
dd1efd8c | 44 | __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp) |
0702b5f4 | 45 | { |
986cab95 | 46 | string_t peername; |
0702b5f4 RM |
47 | size_t len; |
48 | error_t err; | |
49 | ||
0702b5f4 | 50 | if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername))) |
986cab95 | 51 | return __hurd_dfail (fd, err), errno; |
0702b5f4 | 52 | |
986cab95 | 53 | len = __strnlen (peername, sizeof peername - 1) + 1; |
0702b5f4 | 54 | if (len > buflen) |
986cab95 PT |
55 | { |
56 | errno = ERANGE; | |
57 | return ERANGE; | |
58 | } | |
0702b5f4 | 59 | |
dd1efd8c ST |
60 | if (stp) |
61 | { | |
62 | if (__xstat64 (_STAT_VER, peername, stp) < 0) | |
63 | return errno; | |
64 | } | |
65 | ||
0702b5f4 RM |
66 | memcpy (buf, peername, len); |
67 | return 0; | |
68 | } | |
dd1efd8c ST |
69 | |
70 | ||
71 | /* Store at most BUFLEN characters of the pathname of the slave pseudo | |
72 | terminal associated with the master FD is open on in BUF. | |
73 | Return 0 on success, otherwise an error number. */ | |
74 | int | |
75 | __ptsname_r (int fd, char *buf, size_t buflen) | |
76 | { | |
77 | return __ptsname_internal (fd, buf, buflen, NULL); | |
78 | } | |
0702b5f4 | 79 | weak_alias (__ptsname_r, ptsname_r) |