2N/A/* Pausing execution of the current thread.
2N/A Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
2N/A Written by Bruno Haible <bruno@clisp.org>, 2007.
2N/A
2N/A This program is free software: you can redistribute it and/or modify
2N/A it under the terms of the GNU General Public License as published by
2N/A the Free Software Foundation; either version 3 of the License, or
2N/A (at your option) any later version.
2N/A
2N/A This program is distributed in the hope that it will be useful,
2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A GNU General Public License for more details.
2N/A
2N/A You should have received a copy of the GNU General Public License
2N/A along with this program. If not, see <http://www.gnu.org/licenses/>. */
2N/A
2N/A#include <config.h>
2N/A
2N/A/* Specification. */
2N/A#include <unistd.h>
2N/A
2N/A#include <limits.h>
2N/A
2N/A#include "verify.h"
2N/A
2N/A#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
2N/A
2N/A# define WIN32_LEAN_AND_MEAN /* avoid including junk */
2N/A# include <windows.h>
2N/A
2N/Aunsigned int
2N/Asleep (unsigned int seconds)
2N/A{
2N/A unsigned int remaining;
2N/A
2N/A /* Sleep for 1 second many times, because
2N/A 1. Sleep is not interruptiple by Ctrl-C,
2N/A 2. we want to avoid arithmetic overflow while multiplying with 1000. */
2N/A for (remaining = seconds; remaining > 0; remaining--)
2N/A Sleep (1000);
2N/A
2N/A return remaining;
2N/A}
2N/A
2N/A#elif HAVE_SLEEP
2N/A
2N/A# undef sleep
2N/A
2N/A/* Guarantee unlimited sleep and a reasonable return value. Cygwin
2N/A 1.5.x rejects attempts to sleep more than 49.7 days (2**32
2N/A milliseconds), but uses uninitialized memory which results in a
2N/A garbage answer. */
2N/Aunsigned int
2N/Arpl_sleep (unsigned int seconds)
2N/A{
2N/A /* This requires int larger than 16 bits. */
2N/A verify (UINT_MAX / 49 / 24 / 60 / 60);
2N/A const unsigned int limit = 49 * 24 * 60 * 60;
2N/A while (limit < seconds)
2N/A {
2N/A unsigned int result;
2N/A seconds -= limit;
2N/A result = sleep (limit);
2N/A if (result)
2N/A return seconds + result;
2N/A }
2N/A return sleep (seconds);
2N/A}
2N/A
2N/A#else /* !HAVE_SLEEP */
2N/A
2N/A #error "Please port gnulib sleep.c to your platform, possibly using usleep() or select(), then report this to bug-gnulib."
2N/A
2N/A#endif