From: Daniel Mierswa Date: Mon, 17 Aug 2009 19:22:02 +0000 (+0200) Subject: replace usleep() for systems that don't have them X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=437fa54f0516b39b633937fc20ff24c0dcc44bd7;p=util-linux 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 --- diff --git a/configure.ac b/configure.ac index 8999826a..7e13a61e 100644 --- a/configure.ac +++ b/configure.ac @@ -140,6 +140,7 @@ AC_CHECK_FUNCS( fsync \ getdomainname \ get_current_dir_name \ + usleep \ nanosleep \ personality \ updwtmp \ diff --git a/hwclock/kd.c b/hwclock/kd.c index b0e55d1c..3da87caf 100644 --- a/hwclock/kd.c +++ b/hwclock/kd.c @@ -17,6 +17,7 @@ probe_for_kd_clock() { #include #include "nls.h" +#include "usleep.h" static int con_fd = -1; /* opened by probe_for_kd_clock() */ /* never closed */ 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 */ diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c index 58600b9d..f7bc0005 100644 --- a/login-utils/shutdown.c +++ b/login-utils/shutdown.c @@ -76,6 +76,7 @@ #include "pathnames.h" #include "xstrncpy.h" #include "nls.h" +#include "usleep.h" static void usage(void), int_handler(int), write_user(struct utmp *); static void wall(void), write_wtmp(void), unmount_disks(void); diff --git a/mount/fstab.c b/mount/fstab.c index 82e90f3a..8cd35d64 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -19,6 +19,7 @@ #include "fsprobe.h" #include "pathnames.h" #include "nls.h" +#include "usleep.h" #define streq(s, t) (strcmp ((s), (t)) == 0) diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 4b843736..d75a69f3 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -36,6 +36,7 @@ #include #include "nls.h" +#include "usleep.h" /* constants from legacy PC/AT hardware */ #define RTC_PF 0x40 diff --git a/text-utils/tailf.c b/text-utils/tailf.c index 6a76ef45..ec6e1c46 100644 --- a/text-utils/tailf.c +++ b/text-utils/tailf.c @@ -41,6 +41,7 @@ #include #endif #include "nls.h" +#include "usleep.h" #define DEFAULT_LINES 10