aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/sleep.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/toys/sleep.c b/toys/sleep.c
index ed8523f3..311a2683 100644
--- a/toys/sleep.c
+++ b/toys/sleep.c
@@ -35,7 +35,7 @@ void sleep_main(void)
else {
char *arg;
double d = strtod(*toys.optargs, &arg);
- unsigned long l;
+ struct timespec tv;
// Parse suffix
if (*arg) {
@@ -45,17 +45,7 @@ void sleep_main(void)
d *= imhd[c-mhd];
}
- // wait through the delay
- l = (unsigned long)d;
- d -= l;
- if (l) toys.exitval = sleep(l);
- if (!toys.exitval) {
- unsigned long usec = d * 1000000;
- struct timespec tv = {
- .tv_sec = usec / 1000000,
- .tv_nsec = (usec % 1000000) * 1000
- };
- toys.exitval = nanosleep(&tv, NULL);
- }
+ tv.tv_nsec=1000000000*(d-(tv.tv_sec = (unsigned long)d));
+ toys.exitval = !!nanosleep(&tv, NULL);
}
}