Annotation of coherent/g/usr/bin/script/tty_raw.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * File:       tty_raw.c
                      3:  *
                      4:  * Purpose:    put a tty device into raw mode, and restore its old mode later
                      5:  *
                      6:  * $Log:       tty_raw.c,v $
                      7:  * Revision 1.2  92/06/15  10:04:59  bin
                      8:  * *** empty log message ***
                      9:  * 
                     10:  */
                     11: 
                     12: /*
                     13:  * Includes.
                     14:  */
                     15: #include <sgtty.h>
                     16: 
                     17: /*
                     18:  * Definitions.
                     19:  *     Constants.
                     20:  *     Macros with argument lists.
                     21:  *     Typedefs.
                     22:  *     Enums.
                     23:  */
                     24: typedef unsigned char uchar;
                     25: typedef unsigned int  uint;
                     26: typedef unsigned long ulong;
                     27: 
                     28: /*
                     29:  * Functions.
                     30:  *     Import Functions.
                     31:  *     Export Functions.
                     32:  *     Local Functions.
                     33:  */
                     34: int tty_raw();
                     35: int tty_reset();
                     36: 
                     37: /*
                     38:  * Global Data.
                     39:  *     Import Variables.
                     40:  *     Export Variables.
                     41:  *     Local Variables.
                     42:  */
                     43: static struct sgttyb   save_mode;
                     44: 
                     45: /*
                     46:  * tty_raw()
                     47:  *
                     48:  * Given a file descriptor, put the device into raw mode.
                     49:  * Return 0 on success, -1 on failure.
                     50:  */
                     51: int
                     52: tty_raw(fd)
                     53: int fd;
                     54: {
                     55:        struct sgttyb temp_mode;
                     56: 
                     57:        if (ioctl(fd, TIOCGETP, &temp_mode) < 0)
                     58:                return -1;
                     59:        save_mode = temp_mode;
                     60:        temp_mode.sg_flags |= RAW;
                     61:        temp_mode.sg_flags &= ~ECHO;
                     62:        if (ioctl(fd, TIOCSETP, &temp_mode) < 0)
                     63:                return -1;
                     64:        return 0;
                     65: }
                     66: 
                     67: /*
                     68:  * tty_reset()
                     69:  *
                     70:  * Given a file descriptor, restore the old mode.
                     71:  * Return 0 on success, -1 on failure.
                     72:  */
                     73: int
                     74: tty_reset(fd)
                     75: int fd;
                     76: {
                     77:        if (ioctl(fd, TIOCSETP, &save_mode) < 0)
                     78:                return -1;
                     79:        return 0;
                     80: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.