View | Details | Raw Unified | Return to bug 250062 | Differences between
and this patch

Collapse All | Expand All

(-)b/include/stdlib.h (+1 lines)
Lines 225-230 long mrand48(void); Link Here
225
long	 nrand48(unsigned short[3]);
225
long	 nrand48(unsigned short[3]);
226
int	 posix_openpt(int);
226
int	 posix_openpt(int);
227
char	*ptsname(int);
227
char	*ptsname(int);
228
int	 ptsname_r(int, char *, size_t);
228
int	 putenv(char *);
229
int	 putenv(char *);
229
long	 random(void);
230
long	 random(void);
230
unsigned short
231
unsigned short
(-)b/lib/libc/stdlib/Makefile.inc (-1 / +1 lines)
Lines 50-56 MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3 Link Here
50
MLINKS+=hcreate.3 hcreate_r.3 hcreate.3 hdestroy_r.3 hcreate.3 hsearch_r.3
50
MLINKS+=hcreate.3 hcreate_r.3 hcreate.3 hdestroy_r.3 hcreate.3 hsearch_r.3
51
MLINKS+=insque.3 remque.3
51
MLINKS+=insque.3 remque.3
52
MLINKS+=lsearch.3 lfind.3
52
MLINKS+=lsearch.3 lfind.3
53
MLINKS+=ptsname.3 grantpt.3 ptsname.3 unlockpt.3
53
MLINKS+=ptsname.3 grantpt.3 ptsname.3 ptsname_r.3 ptsname.3 unlockpt.3
54
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 qsort.3 qsort_r.3 \
54
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 qsort.3 qsort_r.3 \
55
	qsort.3 qsort_s.3
55
	qsort.3 qsort_s.3
56
MLINKS+=rand.3 rand_r.3 rand.3 srand.3
56
MLINKS+=rand.3 rand_r.3 rand.3 srand.3
(-)b/lib/libc/stdlib/Symbol.map (+1 lines)
Lines 125-130 FBSD_1.6 { Link Here
125
	qsort_s;
125
	qsort_s;
126
	rand;
126
	rand;
127
	srand;
127
	srand;
128
	ptsname_r;
128
};
129
};
129
130
130
FBSDprivate_1.0 {
131
FBSDprivate_1.0 {
(-)b/lib/libc/stdlib/ptsname.3 (-2 / +26 lines)
Lines 31-42 Link Here
31
.\"
31
.\"
32
.\" $FreeBSD$
32
.\" $FreeBSD$
33
.\"
33
.\"
34
.Dd August 20, 2008
34
.Dd October 9, 2020
35
.Dt PTSNAME 3
35
.Dt PTSNAME 3
36
.Os
36
.Os
37
.Sh NAME
37
.Sh NAME
38
.Nm grantpt ,
38
.Nm grantpt ,
39
.Nm ptsname ,
39
.Nm ptsname ,
40
.Nm ptsname_r ,
40
.Nm unlockpt
41
.Nm unlockpt
41
.Nd pseudo-terminal access functions
42
.Nd pseudo-terminal access functions
42
.Sh LIBRARY
43
.Sh LIBRARY
Lines 47-52 Link Here
47
.Fn grantpt "int fildes"
48
.Fn grantpt "int fildes"
48
.Ft "char *"
49
.Ft "char *"
49
.Fn ptsname "int fildes"
50
.Fn ptsname "int fildes"
51
.Ft "int"
52
.Fn ptsname_r "int fildes" "char *buffer" "size_t buflen"
50
.Ft int
53
.Ft int
51
.Fn unlockpt "int fildes"
54
.Fn unlockpt "int fildes"
52
.Sh DESCRIPTION
55
.Sh DESCRIPTION
Lines 87-98 and Link Here
87
have been called.
90
have been called.
88
.Pp
91
.Pp
89
The
92
The
93
.Fn ptsname_r
94
function is the thread-safe version of
95
.Fn ptsname .
96
The caller must provide storage for the results of the full pathname of
97
the slave device in the
98
.Fa buffer
99
and
100
.Fa bufsize
101
arguments.
102
.Pp
103
The
90
.Fn unlockpt
104
.Fn unlockpt
91
function clears the lock held on the pseudo-terminal pair
105
function clears the lock held on the pseudo-terminal pair
92
for the master device specified with
106
for the master device specified with
93
.Fa fildes .
107
.Fa fildes .
94
.Sh RETURN VALUES
108
.Sh RETURN VALUES
95
.Rv -std grantpt unlockpt
109
.Rv -std grantpt ptsname_r unlockpt
96
.Pp
110
.Pp
97
The
111
The
98
.Fn ptsname
112
.Fn ptsname
Lines 119-124 is not a master pseudo-terminal device. Link Here
119
.El
133
.El
120
.Pp
134
.Pp
121
In addition, the
135
In addition, the
136
.Fn ptsname_r
137
function may set
138
.Va errno
139
to:
140
.Bl -tag -width Er
141
.It Bq Er ERANGE
142
the buffer was too small.
143
.El
144
.Pp
145
In addition, the
122
.Fn grantpt
146
.Fn grantpt
123
function may set
147
function may set
124
.Va errno
148
.Va errno
(-)b/lib/libc/stdlib/ptsname.c (-13 / +41 lines)
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
- 

Return to bug 250062