]>
Commit | Line | Data |
---|---|---|
0702b5f4 RM |
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. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
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 | |
13 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include <errno.h> | |
21 | #include <string.h> | |
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 | { | |
33 | static char peername[1024]; /* XXX */ | |
34 | error_t err; | |
35 | ||
36 | err = __ptsname_r (fd, peername, sizeof (peername)); | |
37 | if (err) | |
38 | __set_errno (err); | |
39 | ||
40 | return err ? NULL : peername; | |
41 | } | |
42 | ||
43 | ||
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) | |
49 | { | |
50 | char peername[1024]; /* XXX */ | |
51 | size_t len; | |
52 | error_t err; | |
53 | ||
54 | peername[0] = '\0'; | |
55 | if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername))) | |
56 | return _hurd_fd_error (fd, err); | |
57 | ||
58 | len = strlen (peername) + 1; | |
59 | if (len > buflen) | |
60 | return ERANGE; | |
61 | ||
62 | memcpy (buf, peername, len); | |
63 | return 0; | |
64 | } | |
65 | weak_alias (__ptsname_r, ptsname_r) |