X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fmisc%2Fpty.c;h=9e201ef3218b41bf8863ebabca04a845ddad70e0;hp=0d25a8368e1e46b769150cc42cd199c4b9790f7f;hb=HEAD;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 diff --git a/src/misc/pty.c b/src/misc/pty.c index 0d25a836..9e201ef3 100644 --- a/src/misc/pty.c +++ b/src/misc/pty.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include "libc.h" +#include "syscall.h" int posix_openpt(int flags) { @@ -19,17 +22,13 @@ int unlockpt(int fd) 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; - if (ioctl (fd, TIOCGPTN, &pty)) - return NULL; - if (pty) for (; pty; pty/=10) *--s = '0' + pty%10; - 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; + int pty, err; + if (!buf) len = 0; + if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return err; + if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE; + return 0; } + +weak_alias(__ptsname_r, ptsname_r);