1 /* vi: set sw=4 ts=4: */
3 * sleep implementation for busybox
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 /* BB_AUDIT SUSv3 compliant */
11 /* BB_AUDIT GNU issues -- fancy version matches except args must be ints. */
12 /* http://www.opengroup.org/onlinepubs/007904975/utilities/sleep.html */
14 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
16 * Rewritten to do proper arg and error checking.
17 * Also, added a 'fancy' configuration to accept multiple args with
18 * time suffixes for seconds, minutes, hours, and days.
23 /* Do not make this applet NOFORK. It breaks ^C-ing of pauses in shells */
26 #if ENABLE_FEATURE_FANCY_SLEEP || ENABLE_FEATURE_FLOAT_SLEEP
27 static const struct suffix_mult sfx
[] = {
36 int sleep_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
37 int sleep_main(int argc UNUSED_PARAM
, char **argv
)
39 #if ENABLE_FEATURE_FLOAT_SLEEP
50 #if ENABLE_FEATURE_FLOAT_SLEEP
52 # if ENABLE_LOCALE_SUPPORT
53 /* undo busybox.c setlocale */
54 setlocale(LC_NUMERIC
, "C");
59 if (strchr(arg
, '.')) {
62 int len
= strspn(arg
, "0123456789.");
73 duration
+= d
* xatoul_sfx(arg
, sfx
);
76 duration
+= xatoul_sfx(arg
, sfx
);
80 ts
.tv_sec
= MAXINT(typeof(ts
.tv_sec
));
82 if (duration
>= 0 && duration
< ts
.tv_sec
) {
84 ts
.tv_nsec
= (duration
- ts
.tv_sec
) * 1000000000;
89 } while (errno
== EINTR
);
91 #elif ENABLE_FEATURE_FANCY_SLEEP
95 duration
+= xatou_range_sfx(*argv
, 0, UINT_MAX
- duration
, sfx
);
101 duration
= xatou(*argv
);
103 // Off. If it's really needed, provide example why
104 //if (sleep(duration)) {
105 // bb_perror_nomsg_and_die();