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)
33 if (usp) *usp = usec; \
37 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
47 return select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
49 #else /* !HAVE_TIMEVAL || !HAVE_SELECT */
54 if (usec >= 500000) /* round */
58 #endif /* !HAVE_TIMEVAL || !HAVE_SELECT */
61 * An incredibly simplistic floating point converter.
63 static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 };
78 for (p = s; p && *p; p++) {
79 if (*p == DECIMAL) /* decimal point */
83 sec = (sec * 10) + (*p - '0');
92 /* Look for up to six digits past a decimal point. */
93 for (n = 0; n < 6 && p[n]; n++) {
94 if (isdigit(p[n]) == 0)
96 usec = (usec * 10) + (p[n] - '0');
99 /* Now convert to millionths */
100 usec *= multiplier[n];
102 if (n == 6 && p[6] && isdigit(p[6]) && p[6] >= '5')
103 usec++; /* round up 1 */
119 if (*list->word->word == '-' || list->next) {
124 if (convert(list->word->word, &sec, &usec)) {
126 return(EXECUTION_SUCCESS);
129 builtin_error("%s: bad sleep interval", list->word->word);
130 return (EXECUTION_FAILURE);
133 static char *sleep_doc[] = {
134 "sleep suspends execution for a minimum of SECONDS[.FRACTION] seconds.",
138 struct builtin sleep_struct = {
143 "sleep seconds[.fraction]",