Lines 41-46
__FBSDID("$FreeBSD$");
Link Here
|
41 |
#include <errno.h> |
41 |
#include <errno.h> |
42 |
#include <paths.h> |
42 |
#include <paths.h> |
43 |
#include <stdlib.h> |
43 |
#include <stdlib.h> |
|
|
44 |
#include <string.h> |
44 |
#include "un-namespace.h" |
45 |
#include "un-namespace.h" |
45 |
|
46 |
|
46 |
/* |
47 |
/* |
Lines 71-93
__strong_reference(__isptmaster, grantpt);
Link Here
|
71 |
__strong_reference(__isptmaster, unlockpt); |
72 |
__strong_reference(__isptmaster, unlockpt); |
72 |
|
73 |
|
73 |
/* |
74 |
/* |
74 |
* ptsname(): return the pathname of the slave pseudo-terminal device |
75 |
* ptsname_r(): return the pathname of the slave pseudo-terminal device |
75 |
* associated with the specified master. |
76 |
* associated with the specified master. |
76 |
*/ |
77 |
*/ |
77 |
char * |
78 |
int |
78 |
ptsname(int fildes) |
79 |
ptsname_r(int fildes, char *buffer, size_t buflen) |
79 |
{ |
80 |
{ |
80 |
static char pt_slave[sizeof _PATH_DEV + SPECNAMELEN] = _PATH_DEV; |
81 |
|
81 |
char *ret = NULL; |
82 |
if (buflen <= sizeof(_PATH_DEV)) { |
|
|
83 |
errno = ERANGE; |
84 |
return (-1); |
85 |
} |
82 |
|
86 |
|
83 |
/* Make sure fildes points to a master device. */ |
87 |
/* Make sure fildes points to a master device. */ |
84 |
if (__isptmaster(fildes) != 0) |
88 |
if (__isptmaster(fildes) != 0) |
85 |
goto done; |
89 |
return (-1); |
|
|
90 |
|
91 |
memcpy(buffer, _PATH_DEV, sizeof(_PATH_DEV)); |
92 |
buffer += sizeof(_PATH_DEV) - 1; |
93 |
buflen -= sizeof(_PATH_DEV) - 1; |
94 |
|
95 |
if (fdevname_r(fildes, buffer, buflen) == NULL) { |
96 |
if (errno == EINVAL) |
97 |
errno = ERANGE; |
98 |
return (-1); |
99 |
} |
100 |
|
101 |
return (0); |
102 |
} |
86 |
|
103 |
|
87 |
if (fdevname_r(fildes, pt_slave + (sizeof _PATH_DEV - 1), |
104 |
/* |
88 |
sizeof pt_slave - (sizeof _PATH_DEV - 1)) != NULL) |
105 |
* ptsname(): return the pathname of the slave pseudo-terminal device |
89 |
ret = pt_slave; |
106 |
* associated with the specified master. |
|
|
107 |
*/ |
108 |
char * |
109 |
ptsname(int fildes) |
110 |
{ |
111 |
static char pt_slave[sizeof _PATH_DEV + SPECNAMELEN]; |
90 |
|
112 |
|
91 |
done: |
113 |
if (ptsname_r(fildes, pt_slave, sizeof(pt_slave)) == 0) |
92 |
return (ret); |
114 |
return (pt_slave); |
|
|
115 |
else |
116 |
return (NULL); |
93 |
} |
117 |
} |
94 |
- |
|
|