Mercurial > hg > toybox
changeset 547:611612a1dd83
Simplify nanosleep call.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 15 Mar 2012 20:49:11 -0500 |
parents | a095c02dc431 |
children | 99cb6ad605ee |
files | toys/sleep.c |
diffstat | 1 files changed, 3 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/sleep.c Wed Mar 14 22:04:06 2012 -0500 +++ b/toys/sleep.c Thu Mar 15 20:49:11 2012 -0500 @@ -35,7 +35,7 @@ else { char *arg; double d = strtod(*toys.optargs, &arg); - unsigned long l; + struct timespec tv; // Parse suffix if (*arg) { @@ -45,17 +45,7 @@ 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); } }