File:
[DVB] /
dietlibc /
libugly /
openpty.c
Revision
1.5:
download - view:
text,
annotated -
select for diffs
Wed Sep 21 07:33:08 2005 UTC (18 years, 8 months ago) by
leitner
Branches:
MAIN
CVS tags:
HEAD
update syscalls
lots of fixes from Markus FX Oberhumer:
* better signal handling error detection
* setjmp.S on i386
* getenv on i386
* sys/stat.h -malign-double fix
* update fcntl.h for MIPS to 2.6.13 version
* jmp_buf is 40*8 instead of 58*8 on ppc64.
* This patch fixes the section of the TOC entries on ppc64
* libstdc++ updates for gcc 4
* remove cstddef and cwchar (no longer needed)
* int -> ssize_t for read and write
* sigjmp.c: __mask_was_saved was not set in all cases!
* another round of ILP64 cleanups
#include <unistd.h>
#include <pty.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
int openpty(int *amaster, int *aslave, char *name, struct termios
*termp, struct winsize *winp) {
int fd;
char buf[20];
#if 0
This is what glibc does:
open("/dev/ptmx", O_RDWR) = 4
statfs("/dev/pts", {f_type=0x1cd1, f_bsize=1024, f_blocks=0, f_bfree=0, f_files=0, f_ffree=0, f_namelen=255}) = 0
ioctl(4, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(4, 0x80045430, [0]) = 0
stat("/dev/pts/0", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
statfs("/dev/pts/0", {f_type=0x1cd1, f_bsize=1024, f_blocks=0, f_bfree=0, f_files=0, f_ffree=0, f_namelen=255}) = 0
ioctl(4, 0x40045431, [0]) = 0
ioctl(4, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(4, 0x80045430, [0]) = 0
stat("/dev/pts/0", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
open("/dev/pts/0", O_RDWR|O_NOCTTY) = 5
#endif
if ((fd=open("/dev/ptmx",O_RDWR))<0) return -1;
#if 0
if (ioctl(fd,TCGETS,&ts)<0) goto kaputt;
#endif
{
int unlock=0;
while (ioctl(fd,TIOCSPTLCK, &unlock)<0) if (errno!=EINTR) goto kaputt;
}
{
int ptyno;
while (ioctl(fd,TIOCGPTN,&ptyno)<0) if (errno!=EINTR) goto kaputt;
strcpy(buf,"/dev/pts/");
__ltostr(buf+9,10,ptyno,10,0);
}
*aslave=open(buf,O_RDWR|O_NOCTTY);
if (*aslave<0) goto kaputt;
*amaster=fd;
if (name) strcpy(name,buf);
if (termp)
while (tcsetattr(*aslave,TCSAFLUSH,termp) && errno==EINTR);
if (winp) while (ioctl(*aslave, TIOCSWINSZ, winp) && errno==EINTR);
return 0;
kaputt:
close(fd);
return -1;
}
LinuxTV legacy CVS <linuxtv.org/cvs>