summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-13 08:35:32 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-13 08:35:32 -0400
commit750b738e53f799443fcfcd3a0751318c072a022f (patch)
treeccce946913f6e5bfef0512fdd2313fd512ef1d3c /src
parente2915eeeea244d3818d5eb7532ed35c6cf43c8fd (diff)
downloadmusl-750b738e53f799443fcfcd3a0751318c072a022f.tar.gz
musl-750b738e53f799443fcfcd3a0751318c072a022f.tar.bz2
musl-750b738e53f799443fcfcd3a0751318c072a022f.tar.xz
musl-750b738e53f799443fcfcd3a0751318c072a022f.zip
add ptsname_r (nonstandard) and split ptsname (standard) to separate file
this eliminates the ugly static buffer in programs that use ptsname_r.
Diffstat (limited to 'src')
-rw-r--r--src/misc/ptsname.c9
-rw-r--r--src/misc/pty.c18
2 files changed, 16 insertions, 11 deletions
diff --git a/src/misc/ptsname.c b/src/misc/ptsname.c
new file mode 100644
index 00000000..4f56781d
--- /dev/null
+++ b/src/misc/ptsname.c
@@ -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;
+}
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 <sys/ioctl.h>
#include <stdio.h>
#include <fcntl.h>
+#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);