sleep.c 667 B

123456789101112131415161718192021222324252627282930
  1. /* sleep.c - Wait for a number of seconds.
  2. *
  3. * Copyright 2007 Rob Landley <rob@landley.net>
  4. * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
  5. *
  6. * See http://opengroup.org/onlinepubs/9699919799/utilities/sleep.html
  7. USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
  8. config SLEEP
  9. bool "sleep"
  10. default y
  11. help
  12. usage: sleep DURATION
  13. Wait before exiting.
  14. DURATION can be a decimal fraction. An optional suffix can be "m"
  15. (minutes), "h" (hours), "d" (days), or "s" (seconds, the default).
  16. */
  17. #include "toys.h"
  18. void sleep_main(void)
  19. {
  20. struct timespec ts;
  21. xparsetimespec(*toys.optargs, &ts);
  22. toys.exitval = !!nanosleep(&ts, NULL);
  23. }