mirror of
https://github.com/fluencelabs/musl
synced 2025-06-26 13:12:03 +00:00
add ptsname_r (nonstandard) and split ptsname (standard) to separate file
this eliminates the ugly static buffer in programs that use ptsname_r.
This commit is contained in:
@ -125,6 +125,7 @@ char *mktemp (char *);
|
|||||||
void *valloc (size_t);
|
void *valloc (size_t);
|
||||||
void *memalign(size_t, size_t);
|
void *memalign(size_t, size_t);
|
||||||
int clearenv(void);
|
int clearenv(void);
|
||||||
|
int ptsname_r(int, char *, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
9
src/misc/ptsname.c
Normal file
9
src/misc/ptsname.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int __ptsname_r(int, char *, size_t);
|
||||||
|
|
||||||
|
char *ptsname(int fd)
|
||||||
|
{
|
||||||
|
static char buf[9 + sizeof(int)*3 + 1];
|
||||||
|
return __ptsname_r(fd, buf, sizeof buf) < 0 ? 0 : buf;
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
int posix_openpt(int flags)
|
int posix_openpt(int flags)
|
||||||
{
|
{
|
||||||
@ -19,17 +20,12 @@ int unlockpt(int fd)
|
|||||||
return ioctl(fd, TIOCSPTLCK, &unlock);
|
return ioctl(fd, TIOCSPTLCK, &unlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ptsname(int fd)
|
int __ptsname_r(int fd, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
static char buf[9 + sizeof(int)*3 + 1];
|
|
||||||
char *s = buf+sizeof(buf)-1;
|
|
||||||
int pty;
|
int pty;
|
||||||
if (ioctl (fd, TIOCGPTN, &pty))
|
if (!buf) len = 0;
|
||||||
return NULL;
|
return -( ioctl (fd, TIOCGPTN, &pty) < 0
|
||||||
if (pty) for (; pty; pty/=10) *--s = '0' + pty%10;
|
|| snprintf(buf, len, "/dev/pts/%d", pty) >= len );
|
||||||
else *--s = '0';
|
|
||||||
s -= 9;
|
|
||||||
s[0] = '/'; s[1] = 'd'; s[2] = 'e'; s[3] = 'v';
|
|
||||||
s[4] = '/'; s[5] = 'p'; s[6] = 't'; s[7] = 's'; s[8] = '/';
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
weak_alias(__ptsname_r, ptsname_r);
|
||||||
|
Reference in New Issue
Block a user