comparison toys/usleep.c @ 648:131571cf708c

Adding usleep
author Elie De Brauwer <eliedebrauwer@gmail.com>
date Wed, 15 Aug 2012 12:53:54 +0200
parents
children
comparison
equal deleted inserted replaced
647:3258d9233753 648:131571cf708c
1 /* vi: set sw=4 ts=4:
2 *
3 * usleep.c - Wait for a number of microseconds.
4 *
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
6 *
7 * No standard.
8
9 USE_USLEEP(NEWTOY(usleep, "<1", TOYFLAG_BIN))
10
11 config USLEEP
12 bool "usleep"
13 default y
14 help
15 usage: usleep MICROSECONDS
16
17 Pause for MICROSECONDS microseconds.
18
19 */
20
21 #include "toys.h"
22
23 void usleep_main(void)
24 {
25 struct timespec tv;
26 long delay = atol(*toys.optargs);
27
28 tv.tv_sec = delay/1000000;
29 tv.tv_nsec = (delay%1000000) * 1000;
30 toys.exitval = !!nanosleep(&tv, NULL);
31
32 }