1
0
Fork 0
forked from nuttx/nuttx-update

libc: Implement posix_openpt

specify here:
https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_openpt.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-02-03 01:42:18 +08:00 committed by Alan Carvalho de Assis
parent ad3f16358e
commit 57c3fce583
2 changed files with 39 additions and 12 deletions

View file

@ -223,6 +223,7 @@ int posix_memalign(FAR void **, size_t, size_t);
/* Pseudo-Terminals */
#ifdef CONFIG_PSEUDOTERM
int posix_openpt(int oflag);
FAR char *ptsname(int fd);
int ptsname_r(int fd, FAR char *buf, size_t buflen);
int unlockpt(int fd);

View file

@ -32,13 +32,43 @@
#include <nuttx/serial/pty.h>
/****************************************************************************
* Private Functions
* Public Functions
****************************************************************************/
static int openmaster(void)
/****************************************************************************
* Name: posix_openpt
*
* Description:
* The posix_openpt() function establish a connection between a master
* device for a pseudo-terminal and a file descriptor. The file descriptor
* is used by other I/O functions that refer to that pseudo-terminal.
*
* The file status flags and file access modes of the open file description
* shall be set according to the value of oflag.
*
* Values for oflag are constructed by a bitwise-inclusive OR of flags from
* the following list, defined in <fcntl.h>:
*
* O_RDWR
* Open for reading and writing.
* O_NOCTTY
* If set posix_openpt() shall not cause the terminal device to become
* the controlling terminal for the process.
*
* The behavior of other values for the oflag argument is unspecified.
*
* Returned Value:
* Upon successful completion, the posix_openpt() function shall open
* a master pseudo-terminal device and return a non-negative integer
* representing the lowest numbered unused file descriptor. Otherwise,
* -1 shall be returned and errno set to indicate the error.
*
****************************************************************************/
int posix_openpt(int oflag)
{
#ifdef CONFIG_PSEUDOTERM_SUSV1
return open("dev/ptmx", O_RDWR);
return open("dev/ptmx", oflag);
#else
int minor;
@ -48,13 +78,13 @@ static int openmaster(void)
int fd;
snprintf(devname, 16, "/dev/pty%d", minor);
fd = open(devname, O_RDWR);
fd = open(devname, oflag);
if (fd < 0)
{
/* Fail, register and try again */
pty_register(minor);
fd = open(devname, O_RDWR);
fd = open(devname, oflag);
}
if (fd >= 0)
@ -67,10 +97,6 @@ static int openmaster(void)
#endif
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: openpty
*
@ -83,8 +109,8 @@ static int openmaster(void)
* the slave will be set to the values in win.
*
* Returned Value:
* If a call to openpty() is not successful, -1 is returned and
* errno is set to indicate the error. Otherwise, return 0.
* If a call to openpty() is not successful, -1 is returned and
* errno is set to indicate the error. Otherwise, return 0.
*
****************************************************************************/
@ -96,7 +122,7 @@ int openpty(FAR int *master, FAR int *slave, FAR char *name,
/* Open the pseudo terminal master */
ret = openmaster();
ret = posix_openpt(O_RDWR);
if (ret < 0)
{
return ret;