From 86873e50825448c55e538a5210f9c4fcb0d87166 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 May 2006 18:03:25 +0000 Subject: Sync nanosleep from gnulib. --- lib/ChangeLog | 6 ++++++ lib/nanosleep.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/ChangeLog b/lib/ChangeLog index 05b0daeac..5e6cb7e49 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2006-05-19 Paul Eggert + + * nanosleep.c [HAVE_SYS_SELECT_H]: Include . + Use the usual Autoconf way to include and/or sys/time.h. + (my_usleep): Don't mishandle maximum value. + 2006-05-15 Jim Meyering Avoid the expense of an fstat, when possible. diff --git a/lib/nanosleep.c b/lib/nanosleep.c index 61fc1b90b..7ffe05d2e 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -1,5 +1,7 @@ /* Provide a replacement for the POSIX nanosleep function. - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. + + Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,9 +29,23 @@ #include #include +#if HAVE_SYS_SELECT_H +# include +#endif #include #include +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + #include #include @@ -57,7 +73,7 @@ sighandler (int sig) suspended = 1; } -/* FIXME: comment */ +/* Suspend execution for at least *TS_DELAY seconds. */ static void my_usleep (const struct timespec *ts_delay) @@ -67,13 +83,20 @@ my_usleep (const struct timespec *ts_delay) tv_delay.tv_usec = (ts_delay->tv_nsec + 999) / 1000; if (tv_delay.tv_usec == 1000000) { - tv_delay.tv_sec++; - tv_delay.tv_usec = 0; + time_t t1 = tv_delay.tv_sec + 1; + if (t1 < tv_delay.tv_sec) + tv_delay.tv_usec = 1000000 - 1; /* close enough */ + else + { + tv_delay.tv_sec = t1; + tv_delay.tv_usec = 0; + } } select (0, NULL, NULL, NULL, &tv_delay); } -/* FIXME: comment */ +/* Suspend execution for at least *REQUESTED_DELAY seconds. The + *REMAINING_DELAY part isn't implemented yet. */ int rpl_nanosleep (const struct timespec *requested_delay, -- cgit v1.2.3-54-g00ecf