X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=NeXT%2Flibposix%2Flibposix.c;fp=NeXT%2Flibposix%2Flibposix.c;h=a9a58872b56a32b1d79bb6c98a54ad832de02831;hp=0000000000000000000000000000000000000000;hb=b5c0cf380b11e37f580e6f2affcb78d5ccedade0;hpb=c178bf94c8aa2e30d3934dde8b5371d05ad41f7e;ds=sidebyside diff --git a/NeXT/libposix/libposix.c b/NeXT/libposix/libposix.c new file mode 100644 index 0000000..a9a5887 --- /dev/null +++ b/NeXT/libposix/libposix.c @@ -0,0 +1,165 @@ +/* Yes, that's right: of all the platforms supported by ppp, + only Mach OpenStep 4.x doesn't support POSIX. Sheesh. + + Stranger still, the POSIX declatations are still in the 4.x header files, + and the gcc -posix still defines _POSIX_SOURCE. So... + we emulate (sometimes badly) the missing POSIX functions. This + is by no means a complete or general POSIX emulation. Just enough + to get us by for ppp, so we don't have to pollute the rest of the + sources of every other (non-braindead) platform. Much of the + code was snarfed from NeXT's 4.0 ppp port, the rest inspired by + "POSIX Programmers Guide" by Donald Lewine. + + Maybe if we complain NeXT will upgrade to BSD4.4 libs like the rest of + the free world (and maybe pink elephants will fly out of my... -KC) + */ + +#include +#include +#include +#include +#include +#include + +int sigemptyset(sigset_t *set) +{ + *set = 0; + return 0; +} + +int sigaddset(sigset_t *set, int signo) +{ + *set |= 1<sa_handler; + vec.sv_mask = act->sa_mask; + vec.sv_flags = act->sa_flags; + + st = sigvec(sig, &vec, &ovec); + + if (oact) { + oact->sa_handler = ovec.sv_handler; + oact->sa_mask = ovec.sv_mask; + oact->sa_flags = ovec.sv_flags; + } + + return st; +} + +int tcgetattr(int fildes, struct termios *tp) +{ + return ioctl(fildes, TIOCGETA, tp); +} + +int tcsetattr(int fd, int opt, const struct termios *t) +{ + int st; + + switch(opt) { + case TCSANOW: + st = ioctl(fd, TIOCSETA, t); + break; + case TCSADRAIN: + st = ioctl(fd, TIOCSETAW, t); + break; + case TCSAFLUSH: + st = ioctl(fd, TIOCSETAF, t); + break; + default: + st = -1; + errno = EINVAL; + break; + } + return st; +} + +/* XXX we ignore duration (which is 0 in chat.c anyway). + */ +int tcsendbreak(int fildes, int duration) +{ + struct timeval sleepytime; + + sleepytime.tv_sec = 0; + sleepytime.tv_usec = 400000; + if (ioctl(fildes, TIOCSBRK, 0) != -1) + { + select(0, 0, 0, 0, &sleepytime); + (void) ioctl(fildes, TIOCCBRK, 0); + } +} + +/* XXX This is the implementation of cfgetospeed from NeXT's ppp-5 + pppd/sys-NeXT.c. I don't know whether returning c_ispeed instead + of c_ospeed is deliberate or a type-o. + */ +speed_t cfgetospeed(const struct termios *t) +{ + return t->c_ispeed; +} + +int cfsetospeed(struct termios *t, int speed) +{ + t->c_ospeed = speed; + return 0; +} + +speed_t cfgetispeed(const struct termios *t) +{ + return t->c_ispeed; +} + +int cfsetispeed(struct termios *t, int speed) +{ + t->c_ispeed = speed; + return 0; +} + +int setsid(void) +{ + int fd; + + setpgrp(0, getpid()); + + if ( (fd = open("/dev/tty", O_RDWR | O_NDELAY)) < 0) + return -1; + ioctl(fd, TIOCNOTTY, NULL); + close(fd); + + return 0; +} + +int waitpid(pid_t pid, int *stat_loc, int options) +{ + if (pid == -1) + pid = 0; + return wait4(pid, (union wait *) stat_loc, options, NULL); +} +