Implement window size passing between real tty and virtual console.
[dragonfly/vkernel-mp.git] / contrib / tar / lib / msleep.c
blob38dfed2a280e62fccbf3f0088239c592843c48c8
1 /* Sleep a given number of milliseconds.
2 Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
3 François Pinard <pinard@iro.umontreal.ca>, 1992.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 /* This code is heavily borrowed from Taylor UUCP 1.03. Ian picks one of
24 usleep, nap, napms, poll, select and sleep, in decreasing order of
25 preference. The sleep function is always available. */
27 /* In many cases, we will sleep if the wanted number of milliseconds
28 is higher than this value. */
29 #define THRESHOLD_FOR_SLEEP 30000
31 /* Include some header files. */
33 #if HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
37 #if HAVE_POLL
38 # if HAVE_STROPTS_H
39 # include <stropts.h>
40 # endif
41 # if HAVE_POLL_H
42 # include <sys/types.h>
43 # include <poll.h>
44 # endif
45 # if !HAVE_STROPTS_H && !HAVE_POLL_H
46 /* We need a definition for struct pollfd, although it doesn't matter
47 what it contains. */
48 struct pollfd
50 int idummy;
52 # endif
53 #else
54 # if HAVE_SELECT
55 # include <sys/time.h>
56 # endif
57 #endif
59 /*---------------------------------------.
60 | Sleep a given number of milliseconds. |
61 `---------------------------------------*/
63 void
64 msleep (milliseconds)
65 int milliseconds;
67 #if HAVE_USLEEP
69 if (milliseconds > 0)
70 usleep (milliseconds * (long) 1000);
72 #else
73 # if HAVE_NAP
75 if (milliseconds > 0)
76 nap ((long) milliseconds);
78 # else
79 # if HAVE_NAPMS
81 if (milliseconds >= THRESHOLD_FOR_SLEEP)
83 sleep (milliseconds / 1000);
84 milliseconds %= 1000;
86 if (milliseconds > 0)
87 napms (milliseconds);
89 # else
90 # if HAVE_POLL
92 struct pollfd sdummy; /* poll(2) checks this address */
94 if (milliseconds >= THRESHOLD_FOR_SLEEP)
96 sleep (milliseconds / 1000);
97 milliseconds %= 1000;
99 if (milliseconds > 0)
100 poll (&sdummy, 0, milliseconds);
102 # else
103 # if HAVE_SELECT
105 struct timeval s;
107 if (milliseconds >= THRESHOLD_FOR_SLEEP)
109 sleep (milliseconds / 1000);
110 milliseconds %= 1000;
112 if (milliseconds > 0)
114 s.tv_sec = milliseconds / 1000;
115 s.tv_usec = (milliseconds % 1000) * (long) 1000;
116 select (0, NULL, NULL, NULL, &s);
119 # else
121 /* Round the time up to the next full second. */
123 if (milliseconds > 0)
124 sleep ((milliseconds + 999) / 1000);
126 # endif
127 # endif
128 # endif
129 # endif
130 #endif