X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fnanosleep.c;h=7ffe05d2eb39cccbd8527f4c470b0eb4f8ac4fdf;hb=111cf856170ccb69de8a3232814cd28e2ba22ffa;hp=fa2078507287e3806dd85dbdbdebfc226fff22c3;hpb=222b0486b7db1b09293e05512873d633440efcb3;p=gnulib.git diff --git a/lib/nanosleep.c b/lib/nanosleep.c index fa2078507..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,14 +29,26 @@ #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 -#if HAVE_UNISTD_H -# include -#endif +#include #include "timespec.h" @@ -59,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) @@ -69,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,