Annotation of 43BSDReno/usr.bin/window/wwtty.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Edward Wang at The University of California, Berkeley.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted provided
        !             9:  * that: (1) source distributions retain this entire copyright notice and
        !            10:  * comment, and (2) distributions including binaries display the following
        !            11:  * acknowledgement:  ``This product includes software developed by the
        !            12:  * University of California, Berkeley and its contributors'' in the
        !            13:  * documentation or other materials provided with the distribution and in
        !            14:  * all advertising materials mentioning features or use of this software.
        !            15:  * Neither the name of the University nor the names of its contributors may
        !            16:  * be used to endorse or promote products derived from this software without
        !            17:  * specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)wwtty.c    3.16 (Berkeley) 6/6/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include "ww.h"
        !            28: #include <fcntl.h>
        !            29: 
        !            30: wwgettty(d, t)
        !            31: register struct ww_tty *t;
        !            32: {
        !            33: #ifndef POSIX_TTY
        !            34:        if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0)
        !            35:                goto bad;
        !            36:        if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0)
        !            37:                goto bad;
        !            38:        if (ioctl(d, TIOCGLTC, (char *)&t->ww_ltchars) < 0)
        !            39:                goto bad;
        !            40:        if (ioctl(d, TIOCLGET, (char *)&t->ww_lmode) < 0)
        !            41:                goto bad;
        !            42:        if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0)
        !            43:                goto bad;
        !            44: #else
        !            45:        if (tcgetattr(d, &t->ww_termios) < 0)
        !            46:                goto bad;
        !            47: #endif
        !            48:        if ((t->ww_fflags = fcntl(d, F_GETFL, 0)) < 0)
        !            49:                goto bad;
        !            50:        return 0;
        !            51: bad:
        !            52:        wwerrno = WWE_SYS;
        !            53:        return -1;
        !            54: }
        !            55: 
        !            56: /*
        !            57:  * Set the modes of tty 'd' to 't'
        !            58:  * 'o' is the current modes.  We set the line discipline only if
        !            59:  * it changes, to avoid unnecessary flushing of typeahead.
        !            60:  */
        !            61: wwsettty(d, t, o)
        !            62: register struct ww_tty *t, *o;
        !            63: {
        !            64: #ifndef POSIX_TTY
        !            65:        /* for buggy tty driver that doesn't wait for output to drain */
        !            66:        int i;
        !            67:        while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0)
        !            68:                usleep(100000);
        !            69:        if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0)
        !            70:                goto bad;
        !            71:        if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0)
        !            72:                goto bad;
        !            73:        if (ioctl(d, TIOCSLTC, (char *)&t->ww_ltchars) < 0)
        !            74:                goto bad;
        !            75:        if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0)
        !            76:                goto bad;
        !            77:        if ((o == 0 || t->ww_ldisc != o->ww_ldisc) &&
        !            78:            ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
        !            79:                goto bad;
        !            80: #else
        !            81:        if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0)
        !            82:                goto bad;
        !            83: #endif
        !            84:        if (fcntl(d, F_SETFL, t->ww_fflags) < 0)
        !            85:                goto bad;
        !            86:        return 0;
        !            87: bad:
        !            88:        wwerrno = WWE_SYS;
        !            89:        return -1;
        !            90: }

unix.superglobalmegacorp.com

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