summaryrefslogtreecommitdiff
path: root/libbb/bb_do_delay.c
diff options
context:
space:
mode:
authorDenys Vlasenko2020-11-29 12:40:25 +0100
committerDenys Vlasenko2020-11-29 12:40:25 +0100
commit6a55b4e403979ba299261816a7ec1bb55bbf3f2b (patch)
treed8eba6a7c1483c33547549b07081e9549baa094c /libbb/bb_do_delay.c
parentb86a9ed699e2c4693167d6ead00ac307bd9c01c6 (diff)
downloadbusybox-6a55b4e403979ba299261816a7ec1bb55bbf3f2b.zip
busybox-6a55b4e403979ba299261816a7ec1bb55bbf3f2b.tar.gz
libbb: introduce and use msleep()
function old new delta msleep - 45 +45 watchdog_main 271 266 -5 common_traceroute_main 3546 3530 -16 beep_main 277 248 -29 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 45/-50) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/bb_do_delay.c')
-rw-r--r--libbb/bb_do_delay.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c
index 3a86dc2..3dbf032 100644
--- a/libbb/bb_do_delay.c
+++ b/libbb/bb_do_delay.c
@@ -8,7 +8,7 @@
*/
#include "libbb.h"
-/* void FAST_FUNC bb_do_delay(int seconds) { ... } - no users yet */
+/* void FAST_FUNC bb_do_delay(unsigned seconds) { ... } - no users yet */
#ifndef LOGIN_FAIL_DELAY
#define LOGIN_FAIL_DELAY 3
@@ -34,3 +34,16 @@ void FAST_FUNC sleep1(void)
sleep(1);
}
+void FAST_FUNC msleep(unsigned ms)
+{
+ /* 1. usleep(n) is not guaranteed by standards to accept n >= 1000000
+ * 2. multiplication in usleep(ms * 1000) can overflow if ms > 4294967
+ * (sleep of ~71.5 minutes)
+ * Let's play safe and loop:
+ */
+ while (ms > 500) {
+ usleep(500000);
+ ms -= 500;
+ }
+ usleep(ms * 1000);
+}