X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fmisc%2Fpty.c;h=6ca33e3169b66fc1874343b21802bf17d788305e;hp=0d25a8368e1e46b769150cc42cd199c4b9790f7f;hb=28af39fe427ffec8b836f4f30450ffc30b03e5c4;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 diff --git a/src/misc/pty.c b/src/misc/pty.c index 0d25a836..6ca33e31 100644 --- a/src/misc/pty.c +++ b/src/misc/pty.c @@ -2,6 +2,7 @@ #include #include #include +#include "libc.h" int posix_openpt(int flags) { @@ -19,17 +20,12 @@ 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; + if (!buf) len = 0; + return -( ioctl (fd, TIOCGPTN, &pty) < 0 + || snprintf(buf, len, "/dev/pts/%d", pty) >= len ); } + +weak_alias(__ptsname_r, ptsname_r);