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 <impulze@impulze.org>
This commit is contained in:
Daniel Mierswa 2009-08-17 21:22:02 +02:00 committed by Karel Zak
parent 102f5d89d9
commit 437fa54f05
8 changed files with 25 additions and 0 deletions

View File

@ -140,6 +140,7 @@ AC_CHECK_FUNCS(
fsync \
getdomainname \
get_current_dir_name \
usleep \
nanosleep \
personality \
updwtmp \

View File

@ -17,6 +17,7 @@ probe_for_kd_clock() {
#include <sys/ioctl.h>
#include "nls.h"
#include "usleep.h"
static int con_fd = -1; /* opened by probe_for_kd_clock() */
/* never closed */

View File

@ -16,6 +16,7 @@ dist_noinst_HEADERS = \
pttype.h \
setproctitle.h \
swapheader.h \
usleep.h \
wholedisk.h \
widechar.h \
xstrncpy.h

18
include/usleep.h Normal file
View File

@ -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 */

View File

@ -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);

View File

@ -19,6 +19,7 @@
#include "fsprobe.h"
#include "pathnames.h"
#include "nls.h"
#include "usleep.h"
#define streq(s, t) (strcmp ((s), (t)) == 0)

View File

@ -36,6 +36,7 @@
#include <linux/rtc.h>
#include "nls.h"
#include "usleep.h"
/* constants from legacy PC/AT hardware */
#define RTC_PF 0x40

View File

@ -41,6 +41,7 @@
#include <sys/inotify.h>
#endif
#include "nls.h"
#include "usleep.h"
#define DEFAULT_LINES 10