diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/sleep.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'coreutils/sleep.c')
-rw-r--r-- | coreutils/sleep.c | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/coreutils/sleep.c b/coreutils/sleep.c index 7bc98d8e8..506192dd3 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c | |||
@@ -1,8 +1,8 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini sleep implementation for busybox | 3 | * sleep implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 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 | 8 | * it under the terms of the GNU General Public License as published by |
@@ -20,18 +20,67 @@ | |||
20 | * | 20 | * |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <stdio.h> | 23 | /* BB_AUDIT SUSv3 compliant */ |
24 | #include <unistd.h> | 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 | |||
25 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <limits.h> | ||
36 | #include <unistd.h> | ||
26 | #include "busybox.h" | 37 | #include "busybox.h" |
27 | 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 | |||
28 | extern int sleep_main(int argc, char **argv) | 49 | extern int sleep_main(int argc, char **argv) |
29 | { | 50 | { |
30 | if ((argc < 2) || (**(argv + 1) == '-')) { | 51 | unsigned int duration; |
31 | show_usage(); | 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(); | ||
32 | } | 83 | } |
33 | 84 | ||
34 | if (sleep(atoi(*(++argv))) != 0) | ||
35 | perror_msg_and_die("sleep"); | ||
36 | return EXIT_SUCCESS; | 85 | return EXIT_SUCCESS; |
37 | } | 86 | } |