xref: /openbsd/lib/libcurses/tinfo/lib_napms.c (revision 404b540a)
1 /*	$OpenBSD: lib_napms.c,v 1.7 2001/01/22 18:01:53 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34  ****************************************************************************/
35 
36 /*
37  *	lib_napms.c
38  *
39  *	The routine napms.
40  *
41  */
42 
43 #include <curses.priv.h>
44 
45 #if HAVE_NANOSLEEP
46 #include <time.h>
47 #if HAVE_SYS_TIME_H
48 #include <sys/time.h>		/* needed for MacOS X DP3 */
49 #endif
50 #elif USE_FUNC_POLL
51 #if HAVE_SYS_TIME_H
52 #include <sys/time.h>
53 #endif
54 #elif HAVE_SELECT
55 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
56 #include <sys/time.h>
57 #endif
58 #if HAVE_SYS_SELECT_H
59 #include <sys/select.h>
60 #endif
61 #endif
62 
63 MODULE_ID("$From: lib_napms.c,v 1.11 2000/12/10 02:55:07 tom Exp $")
64 
65 NCURSES_EXPORT(int)
66 napms(int ms)
67 {
68     T((T_CALLED("napms(%d)"), ms));
69 
70 #if HAVE_NANOSLEEP
71     {
72 	struct timespec ts;
73 	ts.tv_sec = ms / 1000;
74 	ts.tv_nsec = (ms % 1000) * 1000000;
75 	nanosleep(&ts, NULL);
76     }
77 #elif USE_FUNC_POLL
78     {
79 	struct pollfd fds[1];
80 	poll(fds, 0, ms);
81     }
82 #elif HAVE_SELECT
83     {
84 	struct timeval tval;
85 	tval.tv_sec = ms / 1000;
86 	tval.tv_usec = (ms % 1000) * 1000;
87 	select(0, NULL, NULL, NULL, &tval);
88     }
89 #endif
90     returnCode(OK);
91 }
92