pax: avoid implicit function declaration warnings
[unleashed.git] / bin / less / ttyin.c
blob71aac2420176e860be435804244987b4631bba7c
1 /*
2 * Copyright (C) 1984-2012 Mark Nudelman
3 * Modified for use with illumos by Garrett D'Amore.
4 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
13 * Routines dealing with getting input from the keyboard (i.e. from the user).
16 #include "less.h"
18 int tty;
19 extern volatile sig_atomic_t sigs;
20 extern int utf_mode;
23 * Open keyboard for input.
25 void
26 open_getchr(void)
29 * Try /dev/tty.
30 * If that doesn't work, use file descriptor 2,
31 * which in Unix is usually attached to the screen,
32 * but also usually lets you read from the keyboard.
34 tty = open("/dev/tty", O_RDONLY);
35 if (tty < 0)
36 tty = STDERR_FILENO;
40 * Get a character from the keyboard.
42 int
43 getchr(void)
45 unsigned char c;
46 int result;
48 do {
49 result = iread(tty, &c, sizeof (char));
50 if (result == READ_INTR)
51 return (READ_INTR);
52 if (result < 0) {
54 * Don't call error() here,
55 * because error calls getchr!
57 quit(QUIT_ERROR);
60 * Various parts of the program cannot handle
61 * an input character of '\0'.
62 * If a '\0' was actually typed, convert it to '\340' here.
64 if (c == '\0')
65 c = 0340;
66 } while (result != 1);
68 return (c & 0xFF);