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 (buffer == NULL) { |
|
|
83 |
errno = EINVAL; |
84 |
return (-1); |
85 |
} |
86 |
|
87 |
if (buflen <= sizeof(_PATH_DEV)) { |
88 |
errno = ERANGE; |
89 |
return (-1); |
90 |
} |
82 |
|
91 |
|
83 |
/* Make sure fildes points to a master device. */ |
92 |
/* Make sure fildes points to a master device. */ |
84 |
if (__isptmaster(fildes) != 0) |
93 |
if (__isptmaster(fildes) != 0) |
85 |
goto done; |
94 |
return (-1); |
|
|
95 |
|
96 |
memcpy(buffer, _PATH_DEV, sizeof(_PATH_DEV)); |
97 |
buffer += sizeof(_PATH_DEV) - 1; |
98 |
buflen -= sizeof(_PATH_DEV) - 1; |
99 |
|
100 |
if (fdevname_r(fildes, buffer, buflen) != NULL) { |
101 |
if (errno == EINVAL) |
102 |
errno = ERANGE; |
103 |
return (-1); |
104 |
} |
86 |
|
105 |
|
87 |
if (fdevname_r(fildes, pt_slave + (sizeof _PATH_DEV - 1), |
106 |
return (0); |
88 |
sizeof pt_slave - (sizeof _PATH_DEV - 1)) != NULL) |
107 |
} |
89 |
ret = pt_slave; |
108 |
|
|
|
109 |
/* |
110 |
* ptsname(): return the pathname of the slave pseudo-terminal device |
111 |
* associated with the specified master. |
112 |
*/ |
113 |
char * |
114 |
ptsname(int fildes) |
115 |
{ |
116 |
static char pt_slave[sizeof _PATH_DEV + SPECNAMELEN]; |
90 |
|
117 |
|
91 |
done: |
118 |
if (ptsname_r(fildes, pt_slave, sizeof(pt_slave))) |
92 |
return (ret); |
119 |
return (pt_slave); |
|
|
120 |
else |
121 |
return (NULL); |
93 |
} |
122 |
} |
94 |
- |
|
|