Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / lib / isc / win32 / keyboard.c
blobfaa66abc63cdcd4f09a155b4e5413c281a4cbc7a
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: keyboard.c,v 1.7 2007/06/19 23:47:19 tbox Exp */
22 #include <config.h>
24 #include <sys/types.h>
26 #include <windows.h>
27 #include <errno.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <fcntl.h>
34 #include <io.h>
36 #include <isc/keyboard.h>
37 #include <isc/util.h>
39 isc_result_t
40 isc_keyboard_open(isc_keyboard_t *keyboard) {
41 int fd;
43 REQUIRE(keyboard != NULL);
45 fd = _fileno(stdin);
46 if (fd < 0)
47 return (ISC_R_IOERROR);
49 keyboard->fd = fd;
51 keyboard->result = ISC_R_SUCCESS;
53 return (ISC_R_SUCCESS);
56 isc_result_t
57 isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleeptime) {
58 REQUIRE(keyboard != NULL);
60 if (sleeptime > 0 && keyboard->result != ISC_R_CANCELED)
61 (void)Sleep(sleeptime*1000);
63 keyboard->fd = -1;
65 return (ISC_R_SUCCESS);
68 isc_result_t
69 isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp) {
70 ssize_t cc;
71 unsigned char c;
73 REQUIRE(keyboard != NULL);
74 REQUIRE(cp != NULL);
76 cc = read(keyboard->fd, &c, 1);
77 if (cc < 0) {
78 keyboard->result = ISC_R_IOERROR;
79 return (keyboard->result);
82 *cp = c;
84 return (ISC_R_SUCCESS);
87 isc_boolean_t
88 isc_keyboard_canceled(isc_keyboard_t *keyboard) {
89 return (ISC_TF(keyboard->result == ISC_R_CANCELED));