aboutsummaryrefslogtreecommitdiff
path: root/toys/usleep.c
blob: 6efc0c16322fe780605ed2895290c9211d87af1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* vi: set sw=4 ts=4:
 *
 * usleep.c - Wait for a number of microseconds.
 *
 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
 *
 * No standard.

USE_USLEEP(NEWTOY(usleep, "<1", TOYFLAG_BIN))

config USLEEP
	bool "usleep"
	default y
	help
	  usage: usleep MICROSECONDS

	  Pause for MICROSECONDS microseconds.

*/

#include "toys.h"

void usleep_main(void)
{
    struct timespec tv;
    long delay = atol(*toys.optargs);
    
    tv.tv_sec = delay/1000000;
    tv.tv_nsec = (delay%1000000) * 1000;
    toys.exitval = !!nanosleep(&tv, NULL);

}