2 * sleep -- sleep for fractions of a second
4 * usage: sleep seconds[.fraction]
10 #if defined (TIME_WITH_SYS_TIME)
11 # include <sys/time.h>
14 # if defined (HAVE_SYS_TIME_H)
15 # include <sys/time.h>
21 #if defined (HAVE_UNISTD_H)
26 #include "chartypes.h"
34 if (usp) *usp = usec; \
38 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
48 return select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
50 #else /* !HAVE_TIMEVAL || !HAVE_SELECT */
55 if (usec >= 500000) /* round */
59 #endif /* !HAVE_TIMEVAL || !HAVE_SELECT */
62 * An incredibly simplistic floating point converter.
64 static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 };
79 for (p = s; p && *p; p++) {
80 if (*p == DECIMAL) /* decimal point */
84 sec = (sec * 10) + (*p - '0');
93 /* Look for up to six digits past a decimal point. */
94 for (n = 0; n < 6 && p[n]; n++) {
97 usec = (usec * 10) + (p[n] - '0');
100 /* Now convert to millionths */
101 usec *= multiplier[n];
103 if (n == 6 && p[6] >= '5' && p[6] <= '9')
104 usec++; /* round up 1 */
120 if (*list->word->word == '-' || list->next) {
125 if (convert(list->word->word, &sec, &usec)) {
127 return(EXECUTION_SUCCESS);
130 builtin_error("%s: bad sleep interval", list->word->word);
131 return (EXECUTION_FAILURE);
134 static char *sleep_doc[] = {
135 "sleep suspends execution for a minimum of SECONDS[.FRACTION] seconds.",
139 struct builtin sleep_struct = {
144 "sleep seconds[.fraction]",