[BACK]Return to ttyin.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

File: [local] / src / usr.bin / less / ttyin.c (download)

Revision 1.11, Mon Nov 9 03:09:19 2015 UTC (8 years, 6 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_6_5_BASE, OPENBSD_6_5, OPENBSD_6_4_BASE, OPENBSD_6_4, OPENBSD_6_3_BASE, OPENBSD_6_3, OPENBSD_6_2_BASE, OPENBSD_6_2, OPENBSD_6_1_BASE, OPENBSD_6_1, OPENBSD_6_0_BASE, OPENBSD_6_0, OPENBSD_5_9_BASE, OPENBSD_5_9
Changes since 1.10: +0 -8 lines

close_getchr() is now a noop

/*
 * Copyright (C) 1984-2012  Mark Nudelman
 * Modified for use with illumos by Garrett D'Amore.
 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Less License, as specified in the README file.
 *
 * For more information, see the README file.
 */

/*
 * Routines dealing with getting input from the keyboard (i.e. from the user).
 */

#include "less.h"

int tty;
extern volatile sig_atomic_t sigs;
extern int utf_mode;

/*
 * Open keyboard for input.
 */
void
open_getchr(void)
{
	/*
	 * Try /dev/tty.
	 * If that doesn't work, use file descriptor 2,
	 * which in Unix is usually attached to the screen,
	 * but also usually lets you read from the keyboard.
	 */
	tty = open("/dev/tty", O_RDONLY);
	if (tty < 0)
		tty = STDERR_FILENO;
}

/*
 * Get a character from the keyboard.
 */
int
getchr(void)
{
	unsigned char c;
	int result;

	do {
		result = iread(tty, &c, sizeof (char));
		if (result == READ_INTR)
			return (READ_INTR);
		if (result < 0) {
			/*
			 * Don't call error() here,
			 * because error calls getchr!
			 */
			quit(QUIT_ERROR);
		}
		/*
		 * Various parts of the program cannot handle
		 * an input character of '\0'.
		 * If a '\0' was actually typed, convert it to '\340' here.
		 */
		if (c == '\0')
			c = 0340;
	} while (result != 1);

	return (c & 0xFF);
}