]>
git.ipfire.org Git - thirdparty/bash.git/blob - examples/loadables/sleep.c
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.
76 for (p
= s
; p
&& *p
; p
++) {
77 if (*p
== DECIMAL
) /* decimal point */
81 sec
= (sec
* 10) + (*p
- '0');
90 /* Look for up to six digits past a decimal point. */
91 for (n
= 0; n
< 6 && p
[n
]; n
++) {
92 if (isdigit(p
[n
]) == 0)
94 usec
= (usec
* 10) + (p
[n
] - '0');
97 /* Now convert to millionths */
108 else if (n
== 6 && p
[6] && isdigit(p
[6]) && p
[6] >= '5')
109 usec
++; /* round up 1 */
124 if (*list
->word
->word
== '-' || list
->next
) {
129 if (convert(list
->word
->word
, &sec
, &usec
)) {
131 return(EXECUTION_SUCCESS
);
134 builtin_error("%s: bad sleep interval", list
->word
->word
);
135 return (EXECUTION_FAILURE
);
138 static char *sleep_doc
[] = {
139 "sleep suspends execution for a minimum of SECONDS[.FRACTION] seconds.",
143 struct builtin sleep_struct
= {
148 "sleep seconds[.fraction]",