typo fix
[busybox-git.git] / libbb / bb_do_delay.c
blob9a84fa24bfe6c019c6e5c6b188fce1fd6b39d10d
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Busybox utility routines.
5 * Copyright (C) 2005 by Tito Ragusa <tito-wolit@tiscali.it>
7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */
9 #include "libbb.h"
11 /* void FAST_FUNC bb_do_delay(unsigned seconds) { ... } - no users yet */
13 #ifndef LOGIN_FAIL_DELAY
14 #define LOGIN_FAIL_DELAY 3
15 #endif
16 void FAST_FUNC pause_after_failed_login(void)
18 #if 0 /* over-engineered madness */
19 time_t end, diff;
21 end = time(NULL) + LOGIN_FAIL_DELAY;
22 diff = LOGIN_FAIL_DELAY;
23 do {
24 sleep(diff);
25 diff = end - time(NULL);
26 } while (diff > 0);
27 #else
28 sleep(LOGIN_FAIL_DELAY);
29 #endif
32 void FAST_FUNC sleep1(void)
34 sleep(1);
37 void FAST_FUNC msleep(unsigned ms)
39 #if 0
40 /* 1. usleep(n) is not guaranteed by standards to accept n >= 1000000
41 * 2. multiplication in usleep(ms * 1000) can overflow if ms > 4294967
42 * (sleep of ~71.5 minutes)
43 * Let's play safe and loop:
45 while (ms > 500) {
46 usleep(500000);
47 ms -= 500;
49 usleep(ms * 1000);
50 #else
51 //usleep is often implemented as a call to nanosleep.
52 //Simply do the same to implement msleep.
53 //it's marginally larger, but wakes your CPU less often:
54 //function old new delta
55 //msleep 45 52 +7
56 struct timespec ts;
57 ts.tv_sec = ms / 1000;
58 ts.tv_nsec = (ms % 1000) * 1000000;
60 * If a signal has non-default handler, nanosleep returns early.
61 * Our version of msleep doesn't return early
62 * if interrupted by such signals:
64 while (nanosleep(&ts, &ts) != 0)
65 continue;
66 #endif