Implement ptsname_r.
MFC after: 2 weeks PR: 250062 Reviewed by: jilles, 0mp, Ray <i maskray me> Differential Revision: https://reviews.freebsd.org/D26647
This commit is contained in:
parent
180f822596
commit
3e7224dffe
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=366781
@ -225,6 +225,7 @@ long mrand48(void);
|
|||||||
long nrand48(unsigned short[3]);
|
long nrand48(unsigned short[3]);
|
||||||
int posix_openpt(int);
|
int posix_openpt(int);
|
||||||
char *ptsname(int);
|
char *ptsname(int);
|
||||||
|
int ptsname_r(int, char *, size_t);
|
||||||
int putenv(char *);
|
int putenv(char *);
|
||||||
long random(void);
|
long random(void);
|
||||||
unsigned short
|
unsigned short
|
||||||
|
@ -50,7 +50,7 @@ MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3
|
|||||||
MLINKS+=hcreate.3 hcreate_r.3 hcreate.3 hdestroy_r.3 hcreate.3 hsearch_r.3
|
MLINKS+=hcreate.3 hcreate_r.3 hcreate.3 hdestroy_r.3 hcreate.3 hsearch_r.3
|
||||||
MLINKS+=insque.3 remque.3
|
MLINKS+=insque.3 remque.3
|
||||||
MLINKS+=lsearch.3 lfind.3
|
MLINKS+=lsearch.3 lfind.3
|
||||||
MLINKS+=ptsname.3 grantpt.3 ptsname.3 unlockpt.3
|
MLINKS+=ptsname.3 grantpt.3 ptsname.3 ptsname_r.3 ptsname.3 unlockpt.3
|
||||||
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 qsort.3 qsort_r.3 \
|
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3 qsort.3 qsort_r.3 \
|
||||||
qsort.3 qsort_s.3
|
qsort.3 qsort_s.3
|
||||||
MLINKS+=rand.3 rand_r.3 rand.3 srand.3
|
MLINKS+=rand.3 rand_r.3 rand.3 srand.3
|
||||||
|
@ -125,6 +125,7 @@ FBSD_1.6 {
|
|||||||
qsort_s;
|
qsort_s;
|
||||||
rand;
|
rand;
|
||||||
srand;
|
srand;
|
||||||
|
ptsname_r;
|
||||||
};
|
};
|
||||||
|
|
||||||
FBSDprivate_1.0 {
|
FBSDprivate_1.0 {
|
||||||
|
@ -31,12 +31,13 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd August 20, 2008
|
.Dd October 17, 2020
|
||||||
.Dt PTSNAME 3
|
.Dt PTSNAME 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm grantpt ,
|
.Nm grantpt ,
|
||||||
.Nm ptsname ,
|
.Nm ptsname ,
|
||||||
|
.Nm ptsname_r ,
|
||||||
.Nm unlockpt
|
.Nm unlockpt
|
||||||
.Nd pseudo-terminal access functions
|
.Nd pseudo-terminal access functions
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
@ -47,6 +48,8 @@
|
|||||||
.Fn grantpt "int fildes"
|
.Fn grantpt "int fildes"
|
||||||
.Ft "char *"
|
.Ft "char *"
|
||||||
.Fn ptsname "int fildes"
|
.Fn ptsname "int fildes"
|
||||||
|
.Ft "int"
|
||||||
|
.Fn ptsname_r "int fildes" "char *buffer" "size_t buflen"
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn unlockpt "int fildes"
|
.Fn unlockpt "int fildes"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -87,12 +90,23 @@ and
|
|||||||
have been called.
|
have been called.
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
|
.Fn ptsname_r
|
||||||
|
function is the thread-safe version of
|
||||||
|
.Fn ptsname .
|
||||||
|
The caller must provide storage for the results of the full pathname of
|
||||||
|
the slave device in the
|
||||||
|
.Fa buffer
|
||||||
|
and
|
||||||
|
.Fa bufsize
|
||||||
|
arguments.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
.Fn unlockpt
|
.Fn unlockpt
|
||||||
function clears the lock held on the pseudo-terminal pair
|
function clears the lock held on the pseudo-terminal pair
|
||||||
for the master device specified with
|
for the master device specified with
|
||||||
.Fa fildes .
|
.Fa fildes .
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
.Rv -std grantpt unlockpt
|
.Rv -std grantpt ptsname_r unlockpt
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn ptsname
|
.Fn ptsname
|
||||||
@ -103,7 +117,8 @@ pointer is returned.
|
|||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
The
|
The
|
||||||
.Fn grantpt ,
|
.Fn grantpt ,
|
||||||
.Fn ptsname
|
.Fn ptsname ,
|
||||||
|
.Fn ptsname_r
|
||||||
and
|
and
|
||||||
.Fn unlockpt
|
.Fn unlockpt
|
||||||
functions may fail and set
|
functions may fail and set
|
||||||
@ -119,6 +134,16 @@ is not a master pseudo-terminal device.
|
|||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
In addition, the
|
In addition, the
|
||||||
|
.Fn ptsname_r
|
||||||
|
function may set
|
||||||
|
.Va errno
|
||||||
|
to:
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er ERANGE
|
||||||
|
The buffer was too small.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
In addition, the
|
||||||
.Fn grantpt
|
.Fn grantpt
|
||||||
function may set
|
function may set
|
||||||
.Va errno
|
.Va errno
|
||||||
|
@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -70,6 +71,36 @@ __isptmaster(int fildes)
|
|||||||
__strong_reference(__isptmaster, grantpt);
|
__strong_reference(__isptmaster, grantpt);
|
||||||
__strong_reference(__isptmaster, unlockpt);
|
__strong_reference(__isptmaster, unlockpt);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ptsname_r(): return the pathname of the slave pseudo-terminal device
|
||||||
|
* associated with the specified master.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ptsname_r(int fildes, char *buffer, size_t buflen)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (buflen <= sizeof(_PATH_DEV)) {
|
||||||
|
errno = ERANGE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure fildes points to a master device. */
|
||||||
|
if (__isptmaster(fildes) != 0)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
memcpy(buffer, _PATH_DEV, sizeof(_PATH_DEV));
|
||||||
|
buffer += sizeof(_PATH_DEV) - 1;
|
||||||
|
buflen -= sizeof(_PATH_DEV) - 1;
|
||||||
|
|
||||||
|
if (fdevname_r(fildes, buffer, buflen) == NULL) {
|
||||||
|
if (errno == EINVAL)
|
||||||
|
errno = ERANGE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ptsname(): return the pathname of the slave pseudo-terminal device
|
* ptsname(): return the pathname of the slave pseudo-terminal device
|
||||||
* associated with the specified master.
|
* associated with the specified master.
|
||||||
@ -77,17 +108,10 @@ __strong_reference(__isptmaster, unlockpt);
|
|||||||
char *
|
char *
|
||||||
ptsname(int fildes)
|
ptsname(int fildes)
|
||||||
{
|
{
|
||||||
static char pt_slave[sizeof _PATH_DEV + SPECNAMELEN] = _PATH_DEV;
|
static char pt_slave[sizeof _PATH_DEV + SPECNAMELEN];
|
||||||
char *ret = NULL;
|
|
||||||
|
|
||||||
/* Make sure fildes points to a master device. */
|
if (ptsname_r(fildes, pt_slave, sizeof(pt_slave)) == 0)
|
||||||
if (__isptmaster(fildes) != 0)
|
return (pt_slave);
|
||||||
goto done;
|
else
|
||||||
|
return (NULL);
|
||||||
if (fdevname_r(fildes, pt_slave + (sizeof _PATH_DEV - 1),
|
|
||||||
sizeof pt_slave - (sizeof _PATH_DEV - 1)) != NULL)
|
|
||||||
ret = pt_slave;
|
|
||||||
|
|
||||||
done:
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user