aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-03-15 20:49:11 -0500
committerRob Landley <rob@landley.net>2012-03-15 20:49:11 -0500
commitbc329417f840d8073d4e5af7e2c8b23bb32e149c (patch)
tree217e2e1328b4af19c1f0f674ee33d62189162001 /toys
parent16a29268033609664500b3333537cd62fcff50fb (diff)
downloadtoybox-bc329417f840d8073d4e5af7e2c8b23bb32e149c.tar.gz
Simplify nanosleep call.
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);
}
}