From 2a31396a9cee344fcc3a4d34f5e26954fccc6e16 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Oct 2012 11:03:09 +0200 Subject: include/c: move usleep() fallback to c.h To make it available everywhere in code. Signed-off-by: Karel Zak --- include/c.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/c.h') diff --git a/include/c.h b/include/c.h index e343778b4..110728797 100644 --- a/include/c.h +++ b/include/c.h @@ -241,6 +241,21 @@ static inline size_t get_hostname_max(void) return 64; } +#ifndef HAVE_USLEEP +/* + * This function is marked obsolete in POSIX.1-2001 and removed in + * POSIX.1-2008. It is replaced with nanosleep(). + */ +static inline usleep(useconds_t usec) +{ + struct timespec waittime = { + .tv_sec = usec / 1000000L, + .tv_nsec = (usec % 1000000L) * 1000 + } + nanosleep(&waittime, NULL); +} +#endif + /* * Constant strings for usage() functions. For more info see * Documentation/howto-usage-function.txt and sys-utils/arch.c -- cgit v1.2.3-55-g7522