diff options
author | Rob Landley <rob@landley.net> | 2012-03-15 20:49:11 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2012-03-15 20:49:11 -0500 |
commit | bc329417f840d8073d4e5af7e2c8b23bb32e149c (patch) | |
tree | 217e2e1328b4af19c1f0f674ee33d62189162001 | |
parent | 16a29268033609664500b3333537cd62fcff50fb (diff) | |
download | toybox-bc329417f840d8073d4e5af7e2c8b23bb32e149c.tar.gz |
Simplify nanosleep call.
-rw-r--r-- | toys/sleep.c | 16 |
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); } } |