From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/misc/pty.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/misc/pty.c (limited to 'src/misc/pty.c') diff --git a/src/misc/pty.c b/src/misc/pty.c new file mode 100644 index 00000000..0d25a836 --- /dev/null +++ b/src/misc/pty.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +int posix_openpt(int flags) +{ + return open("/dev/ptmx", flags); +} + +int grantpt(int fd) +{ + return 0; +} + +int unlockpt(int fd) +{ + int unlock = 0; + return ioctl(fd, TIOCSPTLCK, &unlock); +} + +char *ptsname(int fd) +{ + 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; +} -- cgit v1.2.1