diff --git a/forkpty-aix.c b/forkpty-aix.c index ff446d3..db1c3d9 100644 --- a/forkpty-aix.c +++ b/forkpty-aix.c @@ -17,23 +17,13 @@ #include #include - #include #include #include #include #include -/* Fatal errors. */ -#ifdef NDEBUG - #define debug(format, args...) -#else - #define debug eprint -#endif -#define fatal(msg) debug("%s: %s", __func__, msg); - -pid_t -forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) +pid_t forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) { int slave, fd; char *path; @@ -41,7 +31,7 @@ forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) struct termios tio2; if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1) - return (-1); + return -1; if ((path = ttyname(*master)) == NULL) goto out; @@ -61,47 +51,47 @@ forkpty(int *master, char *name, struct termios *tio, struct winsize *ws) } if (setsid() < 0) - fatal("setsid"); + return -1; fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); if (fd >= 0) - fatal("open succeeded (failed to disconnect)"); + return -1; fd = open(path, O_RDWR); if (fd < 0) - fatal("open failed"); + return -1; close(fd); fd = open("/dev/tty", O_WRONLY); if (fd < 0) - fatal("open failed"); + return -1; close(fd); if (tcgetattr(slave, &tio2) != 0) - fatal("tcgetattr failed"); + return -1; if (tio != NULL) memcpy(tio2.c_cc, tio->c_cc, sizeof tio2.c_cc); tio2.c_cc[VERASE] = '\177'; if (tcsetattr(slave, TCSAFLUSH, &tio2) == -1) - fatal("tcsetattr failed"); + return -1; if (ioctl(slave, TIOCSWINSZ, ws) == -1) - fatal("ioctl failed"); + return -1; dup2(slave, 0); dup2(slave, 1); dup2(slave, 2); if (slave > 2) close(slave); - return (0); + return 0; } close(slave); - return (pid); + return pid; out: if (*master != -1) close(*master); if (slave != -1) close(slave); - return (-1); + return -1; }