mirror of
https://review.haiku-os.org/haiku
synced 2024-11-23 07:18:40 +01:00
libroot: add ptsname_r for POSIX.1/2024
Change-Id: I9996ff998b2b52a65a101cf7075a3ffb37220962 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8519 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
8b5cc9cf52
commit
7a4e12b7b8
@ -183,6 +183,7 @@ extern int getsubopt(char **optionp, char * const *keylistp,
|
||||
extern int posix_openpt(int openFlags);
|
||||
extern int grantpt(int masterFD);
|
||||
extern char* ptsname(int masterFD);
|
||||
extern int ptsname_r(int masterFD, char *path, size_t maxSize);
|
||||
extern int unlockpt(int masterFD);
|
||||
|
||||
/* internal accessor to value for MB_CUR_MAX */
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -27,19 +28,30 @@ grantpt(int masterFD)
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
ptsname(int masterFD)
|
||||
int
|
||||
ptsname_r(int masterFD, char* name, size_t namesize)
|
||||
{
|
||||
int32 index;
|
||||
if (ioctl(masterFD, B_IOCTL_GET_TTY_INDEX, &index, sizeof(index)) < 0)
|
||||
return NULL;
|
||||
return errno;
|
||||
|
||||
if (name == NULL)
|
||||
return EINVAL;
|
||||
|
||||
static char buffer[32];
|
||||
|
||||
char letter = 'p';
|
||||
snprintf(buffer, sizeof(buffer), "/dev/tt/%c%" B_PRIx32,
|
||||
char(letter + index / 16), index % 16);
|
||||
int length = snprintf(name, namesize, "/dev/tt/%c%" B_PRIx32, char(letter + index / 16),
|
||||
index % 16);
|
||||
return (length + 1) > (int)namesize ? ERANGE : 0;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
ptsname(int masterFD)
|
||||
{
|
||||
static char buffer[32];
|
||||
errno = ptsname_r(masterFD, buffer, sizeof(buffer));
|
||||
if (errno != 0 && errno != ERANGE)
|
||||
return NULL;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -47,6 +59,7 @@ ptsname(int masterFD)
|
||||
int
|
||||
unlockpt(int masterFD)
|
||||
{
|
||||
// Noting to do ATM.
|
||||
// Nothing to do ATM.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user