From 437fa54f0516b39b633937fc20ff24c0dcc44bd7 Mon Sep 17 00:00:00 2001 From: Daniel Mierswa Date: Mon, 17 Aug 2009 21:22:02 +0200 Subject: replace usleep() for systems that don't have them This function is marked obsolete in POSIX.1-2001 and removed in POSIX.1-2008. Conditionally replaced with nanosleep(). Signed-off-by: Daniel Mierswa --- include/Makefile.am | 1 + include/usleep.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 include/usleep.h (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index f959659a..5669421b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,7 @@ dist_noinst_HEADERS = \ pttype.h \ setproctitle.h \ swapheader.h \ + usleep.h \ wholedisk.h \ widechar.h \ xstrncpy.h diff --git a/include/usleep.h b/include/usleep.h new file mode 100644 index 00000000..f64477c9 --- /dev/null +++ b/include/usleep.h @@ -0,0 +1,18 @@ +#ifndef UTIL_LINUX_USLEEP_H +#define UTIL_LINUX_USLEEP_H + +#ifndef HAVE_USLEEP +/* + * This function is marked obsolete in POSIX.1-2001 and removed in + * POSIX.1-2008. It is replaced with nanosleep(). + */ +# define usleep(x) \ + do { \ + struct timespec xsleep; \ + xsleep.tv_sec = x / 1000 / 1000; \ + xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \ + nanosleep(&xsleep, NULL); \ + } while (0) +#endif + +#endif /* UTIL_LINUX_USLEEP_H */ -- cgit v1.2.3