This patch adds a conditional feature to sleep to enable
fractional arguments to sleep (not to fancy sleep though).
Cost is: 118 bytes for code + 2*23 for help.
Another thing: both coreutil/{u,}sleep.c are NOFORK and
call bb_perror_nosmg_and_die(); is it correct ?
Loïc Grenié
Index: coreutils/sleep.c
===================================================================
--- coreutils/sleep.c (revision 20460)
+++ coreutils/sleep.c (working copy)
@@ -37,6 +37,10 @@
int sleep_main(int argc, char **argv)
{
unsigned duration;
+#if ENABLE_FEATURE_FLOAT_SLEEP
+ float duration_float;
+ unsigned duration_rest;
+#endif
#if ENABLE_FEATURE_FANCY_SLEEP
@@ -56,13 +60,34 @@
bb_show_usage();
}
+#if ENABLE_FEATURE_FLOAT_SLEEP
+ duration_float = strtof(argv[1], NULL);
+#if 0
+ /*
+ * The day in which someone will need to sleep for more than 4E9 seconds
+ * (s)he can enable the code below for a cost of 51 bytes (i386).
+ */
+ while (duration_float >= UINT_MAX) {
+ sleep(UINT_MAX);
+ duration_float -= UINT_MAX;
+ }
+#endif
+ duration = duration_float;
+ duration_rest = (duration_float - duration)*1000000;
+#else
duration = xatou(argv[1]);
+#endif
#endif /* FEATURE_FANCY_SLEEP */
if (sleep(duration)) {
bb_perror_nomsg_and_die();
}
+#if ENABLE_FEATURE_FLOAT_SLEEP
+ if (usleep(duration_rest)) {
+ bb_perror_nomsg_and_die();
+ }
+#endif
return EXIT_SUCCESS;
}
Index: coreutils/Config.in
===================================================================
--- coreutils/Config.in (revision 20460)
+++ coreutils/Config.in (working copy)
@@ -513,6 +513,13 @@
help
Allow sleep to pause for specified minutes, hours, and days.
+config FEATURE_FLOAT_SLEEP
+ bool "Enable fractional argument"
+ default n
+ depends on !FEATURE_FANCY_SLEEP
+ help
+ Allow sleep to pause for non integer time.
+
config SORT
bool "sort"
default n
Index: include/usage.h
===================================================================
--- include/usage.h (revision 20460)
+++ include/usage.h (working copy)
@@ -3231,9 +3231,11 @@
"\n -F Disable RTS/CTS flow control" \
#define sleep_trivial_usage \
- USE_FEATURE_FANCY_SLEEP("[") "N" USE_FEATURE_FANCY_SLEEP("]...")
+ USE_FEATURE_FANCY_SLEEP("[") "N" USE_FEATURE_FANCY_SLEEP("]...") \
+ USE_FEATURE_FLOAT_SLEEP("[.F]")
#define sleep_full_usage \
- SKIP_FEATURE_FANCY_SLEEP("Pause for N seconds") \
+ SKIP_FEATURE_FANCY_SLEEP("Pause for N" \
+ USE_FEATURE_FLOAT_SLEEP(" (or N.F)") " seconds") \
USE_FEATURE_FANCY_SLEEP( \
"Pause for a time equal to the total of the args given, where each arg can\n" \
"have an optional suffix of (s)econds, (m)inutes, (h)ours, or (d)ays")
@@ -3242,7 +3244,10 @@
"[2 second delay results]\n" \
USE_FEATURE_FANCY_SLEEP( \
"$ sleep 1d 3h 22m 8s\n" \
- "[98528 second delay results]\n")
+ "[98528 second delay results]\n") \
+ USE_FEATURE_FLOAT_SLEEP( \
+ "$ sleep 2.3\n" \
+ "[2.3 second delay results]\n")
#define sort_trivial_usage \
"[-nru" \
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox