10f66f451Sopenharmony_ci/* sleep.c - Wait for a number of seconds.
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2007 Rob Landley <rob@landley.net>
40f66f451Sopenharmony_ci * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org>
50f66f451Sopenharmony_ci *
60f66f451Sopenharmony_ci * See http://opengroup.org/onlinepubs/9699919799/utilities/sleep.html
70f66f451Sopenharmony_ci
80f66f451Sopenharmony_ciUSE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
90f66f451Sopenharmony_ci
100f66f451Sopenharmony_ciconfig SLEEP
110f66f451Sopenharmony_ci  bool "sleep"
120f66f451Sopenharmony_ci  default y
130f66f451Sopenharmony_ci  help
140f66f451Sopenharmony_ci    usage: sleep DURATION
150f66f451Sopenharmony_ci
160f66f451Sopenharmony_ci    Wait before exiting.
170f66f451Sopenharmony_ci
180f66f451Sopenharmony_ci    DURATION can be a decimal fraction. An optional suffix can be "m"
190f66f451Sopenharmony_ci    (minutes), "h" (hours), "d" (days), or "s" (seconds, the default).
200f66f451Sopenharmony_ci*/
210f66f451Sopenharmony_ci
220f66f451Sopenharmony_ci#include "toys.h"
230f66f451Sopenharmony_ci
240f66f451Sopenharmony_civoid sleep_main(void)
250f66f451Sopenharmony_ci{
260f66f451Sopenharmony_ci  struct timespec ts;
270f66f451Sopenharmony_ci
280f66f451Sopenharmony_ci  xparsetimespec(*toys.optargs, &ts);
290f66f451Sopenharmony_ci  toys.exitval = !!nanosleep(&ts, NULL);
300f66f451Sopenharmony_ci}
31