--- libaitio/src/pty.c 2011/09/30 14:26:57 1.1.2.12 +++ libaitio/src/pty.c 2016/08/10 15:18:23 1.7.8.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: pty.c,v 1.1.2.12 2011/09/30 14:26:57 misho Exp $ +* $Id: pty.c,v 1.7.8.1 2016/08/10 15:18:23 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -47,7 +47,8 @@ SUCH DAMAGE. /* - * ioAllocPTY() Allocate new PTY and TTY + * ioAllocPTY() - Allocate new PTY and TTY + * * @ptyfd = master fd, pty * @ttyfd = slave fd, tty * @name = tty device name if not null @@ -56,13 +57,13 @@ SUCH DAMAGE. * @winz = winsize for terminal * return: -1 error or 0 ok */ -inline int +int ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz, struct termios * __restrict term, struct winsize * __restrict winz) { assert(ptyfd && ttyfd); if (!ptyfd || !ttyfd || (name && namesiz < 64)) { - io_SetErr(EINVAL, "Error:: invalid arguments ..."); + io_SetErr(EINVAL, "Invalid arguments"); return -1; } @@ -76,12 +77,13 @@ ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict n } /* - * ioFreePTY() Release PTY and TTY device + * ioFreePTY() - Release PTY and TTY device + * * @ptyfd = master fd, pty (==-1 skip closing pty) * @ttyname = tty filename * return: none */ -inline void +void ioFreePTY(int ptyfd, const char *ttyname) { assert(ttyname); @@ -90,14 +92,15 @@ ioFreePTY(int ptyfd, const char *ttyname) if (ptyfd != -1) close(ptyfd); - if (ttyname) { + if (*ttyname) { chown(ttyname, (uid_t) 0, (gid_t) 0); chmod(ttyname, (mode_t) 0666); } } /* - * ioChgWinPTY() Change window size of PTY + * ioChgWinPTY() - Change window size of PTY + * * @ptyfd = master fd, pty * @row = row * @col = col @@ -105,7 +108,7 @@ ioFreePTY(int ptyfd, const char *ttyname) * @ypxl = y pixels * return: -1 error or 0 ok */ -inline int +int ioChgWinPTY(int ptyfd, u_short row, u_short col, u_short xpxl, u_short ypxl) { struct winsize w; @@ -124,7 +127,8 @@ ioChgWinPTY(int ptyfd, u_short row, u_short col, u_sho } /* - * ioSetOwnerTTY() Set owner to TTY + * ioSetOwnerTTY() - Set owner to TTY + * * @ttyname = tty filename * @UID = uid * @GID = gid @@ -140,7 +144,7 @@ ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GI assert(ttyname); if (!ttyname) { - io_SetErr(EINVAL, "Error:: invalid arguments ..."); + io_SetErr(EINVAL, "Invalid arguments"); return -1; } @@ -173,7 +177,8 @@ ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GI } /* - * ioSetSidTTY() Makes the process's controlling TTY and sets it to sane modes. + * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes. + * * @ttyfd = slave fd, tty * @ttyname = tty filename * return: -1 error or 0 ok @@ -196,7 +201,7 @@ ioSetSidTTY(int *ttyfd, const char *ttyname) /* Verify that we are successfully disconnected from the controlling tty. */ fd = open(_PATH_TTY, O_RDWR | O_NOCTTY); if (fd >= 0) { - io_SetErr(ENXIO, "Error:: Failed to disconnect from controlling tty."); + io_SetErr(ENXIO, "Failed to disconnect from controlling tty"); close(fd); return -1; } @@ -234,12 +239,13 @@ ioSetSidTTY(int *ttyfd, const char *ttyname) } /* - * ioSetRAWMode() Enter into RAW mode + * ioSetRAWMode() - Enter into RAW mode + * * @fd = tty fd * @otio = saved old termios for later restore if !=NULL * return: -1 error or 0 ok */ -inline int +int ioSetRAWMode(int fd, struct termios *otio) { struct termios tio; @@ -273,12 +279,13 @@ ioSetRAWMode(int fd, struct termios *otio) } /* - * ioRestoreMode() Restore termios to tty fd + * ioRestoreMode() - Restore termios to tty fd + * * @fd = tty fd * @tio = termios structure for restore * return: -1 error or 0 ok */ -inline int +int ioRestoreMode(int fd, struct termios tio) { if (tcsetattr(fd, TCSADRAIN, &tio) == -1) { @@ -290,7 +297,8 @@ ioRestoreMode(int fd, struct termios tio) } /* - * ioForkPTY() Fork new process with session leader and new TTY + * ioForkPTY() - Fork new process with session leader and new TTY + * * @ptyfd = master fd, pty * @name = tty device name if not null * @namesiz = name length, must be above 63 bytes.