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