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