usleep.c 500 B

1234567891011121314151617181920212223242526
  1. /* usleep.c - Wait for a number of microseconds.
  2. *
  3. * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
  4. USE_USLEEP(NEWTOY(usleep, "<1", TOYFLAG_BIN))
  5. config USLEEP
  6. bool "usleep"
  7. default y
  8. help
  9. usage: usleep MICROSECONDS
  10. Pause for MICROSECONDS microseconds.
  11. */
  12. #include "toys.h"
  13. void usleep_main(void)
  14. {
  15. struct timespec tv;
  16. long delay = atol(*toys.optargs);
  17. tv.tv_sec = delay/1000000;
  18. tv.tv_nsec = (delay%1000000) * 1000;
  19. toys.exitval = !!nanosleep(&tv, NULL);
  20. }