From ea648e70a989cca190cd7403fe892fd2dcc290b4 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 20:37:14 +0200 Subject: Adding upstream version 1:9.11.5.P4+dfsg. Signed-off-by: Daniel Baumann --- lib/isc/win32/keyboard.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 lib/isc/win32/keyboard.c (limited to 'lib/isc/win32/keyboard.c') diff --git a/lib/isc/win32/keyboard.c b/lib/isc/win32/keyboard.c new file mode 100644 index 0000000..6e6f800 --- /dev/null +++ b/lib/isc/win32/keyboard.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +isc_result_t +isc_keyboard_open(isc_keyboard_t *keyboard) { + int fd; + + REQUIRE(keyboard != NULL); + + fd = _fileno(stdin); + if (fd < 0) + return (ISC_R_IOERROR); + + keyboard->fd = fd; + + keyboard->result = ISC_R_SUCCESS; + + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleeptime) { + REQUIRE(keyboard != NULL); + + if (sleeptime > 0 && keyboard->result != ISC_R_CANCELED) + (void)Sleep(sleeptime*1000); + + keyboard->fd = -1; + + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp) { + ssize_t cc; + unsigned char c; + + REQUIRE(keyboard != NULL); + REQUIRE(cp != NULL); + + cc = read(keyboard->fd, &c, 1); + if (cc < 0) { + keyboard->result = ISC_R_IOERROR; + return (keyboard->result); + } + + *cp = c; + + return (ISC_R_SUCCESS); +} + +bool +isc_keyboard_canceled(isc_keyboard_t *keyboard) { + return (keyboard->result == ISC_R_CANCELED); +} -- cgit v1.2.3