diff options
Diffstat (limited to 'busybox/coreutils/sleep.c')
-rw-r--r-- | busybox/coreutils/sleep.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/busybox/coreutils/sleep.c b/busybox/coreutils/sleep.c new file mode 100644 index 000000000..506192dd3 --- /dev/null +++ b/busybox/coreutils/sleep.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * sleep implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | /* BB_AUDIT SUSv3 compliant */ | ||
24 | /* BB_AUDIT GNU issues -- fancy version matches except args must be ints. */ | ||
25 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/sleep.html */ | ||
26 | |||
27 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
28 | * | ||
29 | * Rewritten to do proper arg and error checking. | ||
30 | * Also, added a 'fancy' configuration to accept multiple args with | ||
31 | * time suffixes for seconds, minutes, hours, and days. | ||
32 | */ | ||
33 | |||
34 | #include <stdlib.h> | ||
35 | #include <limits.h> | ||
36 | #include <unistd.h> | ||
37 | #include "busybox.h" | ||
38 | |||
39 | #ifdef CONFIG_FEATURE_FANCY_SLEEP | ||
40 | static const struct suffix_mult sleep_suffixes[] = { | ||
41 | { "s", 1 }, | ||
42 | { "m", 60 }, | ||
43 | { "h", 60*60 }, | ||
44 | { "d", 24*60*60 }, | ||
45 | { NULL, 0 } | ||
46 | }; | ||
47 | #endif | ||
48 | |||
49 | extern int sleep_main(int argc, char **argv) | ||
50 | { | ||
51 | unsigned int duration; | ||
52 | |||
53 | #ifdef CONFIG_FEATURE_FANCY_SLEEP | ||
54 | |||
55 | if (argc < 2) { | ||
56 | bb_show_usage(); | ||
57 | } | ||
58 | |||
59 | ++argv; | ||
60 | duration = 0; | ||
61 | do { | ||
62 | duration += bb_xgetularg_bnd_sfx(*argv, 10, | ||
63 | 0, UINT_MAX-duration, | ||
64 | sleep_suffixes); | ||
65 | } while (*++argv); | ||
66 | |||
67 | #else /* CONFIG_FEATURE_FANCY_SLEEP */ | ||
68 | |||
69 | if (argc != 2) { | ||
70 | bb_show_usage(); | ||
71 | } | ||
72 | |||
73 | #if UINT_MAX == ULONG_MAX | ||
74 | duration = bb_xgetularg10(argv[1]); | ||
75 | #else | ||
76 | duration = bb_xgetularg10_bnd(argv[1], 0, UINT_MAX); | ||
77 | #endif | ||
78 | |||
79 | #endif /* CONFIG_FEATURE_FANCY_SLEEP */ | ||
80 | |||
81 | if (sleep(duration)) { | ||
82 | bb_perror_nomsg_and_die(); | ||
83 | } | ||
84 | |||
85 | return EXIT_SUCCESS; | ||
86 | } | ||