No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / external / bsd / openssh / dist / sshtty.c
blobfa8439c644161cbdd65ada418094d929fcea8496
1 /* $NetBSD$ */
2 /* $OpenBSD: sshtty.c,v 1.13 2008/05/19 15:45:07 djm Exp $ */
3 /*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
5 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 * All rights reserved
8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
15 * Copyright (c) 2001 Markus Friedl. All rights reserved.
16 * Copyright (c) 2001 Kevin Steves. All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include "includes.h"
40 __RCSID("$NetBSD: sshtty.c,v 1.5 2009/02/16 20:53:55 christos Exp $");
41 #include <sys/types.h>
42 #include <stdio.h>
43 #include <termios.h>
44 #include <pwd.h>
46 #include "sshpty.h"
48 static struct termios _saved_tio;
49 static int _in_raw_mode = 0;
51 struct termios *
52 get_saved_tio(void)
54 return _in_raw_mode ? &_saved_tio : NULL;
57 void
58 leave_raw_mode(void)
60 if (!_in_raw_mode)
61 return;
62 if (tcsetattr(fileno(stdin), TCSADRAIN, &_saved_tio) == -1)
63 perror("tcsetattr");
64 else
65 _in_raw_mode = 0;
68 void
69 enter_raw_mode(void)
71 struct termios tio;
73 if (tcgetattr(fileno(stdin), &tio) == -1) {
74 perror("tcgetattr");
75 return;
77 _saved_tio = tio;
78 tio.c_iflag |= IGNPAR;
79 tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
80 #ifdef IUCLC
81 tio.c_iflag &= ~IUCLC;
82 #endif
83 tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
84 #ifdef IEXTEN
85 tio.c_lflag &= ~IEXTEN;
86 #endif
87 tio.c_oflag &= ~OPOST;
88 tio.c_cc[VMIN] = 1;
89 tio.c_cc[VTIME] = 0;
90 if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
91 perror("tcsetattr");
92 else
93 _in_raw_mode = 1;