From be8efac78d067c138ad8dda03df4336e73f94887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Jan 2022 11:51:07 +0100 Subject: New upstream version 1.0 --- tests/usleep.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'tests/usleep.c') diff --git a/tests/usleep.c b/tests/usleep.c index a057f5f8..e4289c4a 100644 --- a/tests/usleep.c +++ b/tests/usleep.c @@ -1,18 +1,18 @@ /* Pausing execution of the current thread. - Copyright (C) 2009-2018 Free Software Foundation, Inc. + Copyright (C) 2009-2022 Free Software Foundation, Inc. Written by Eric Blake , 2009. - 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 - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ /* This file is _intentionally_ light-weight. Rather than using @@ -28,6 +28,11 @@ #include +#if defined _WIN32 && ! defined __CYGWIN__ +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include +#endif + #ifndef HAVE_USLEEP # define HAVE_USLEEP 0 #endif @@ -39,7 +44,20 @@ int usleep (useconds_t micro) +#undef usleep { +#if defined _WIN32 && ! defined __CYGWIN__ + unsigned int milliseconds = micro / 1000; + if (sizeof milliseconds < sizeof micro && micro / 1000 != milliseconds) + { + errno = EINVAL; + return -1; + } + if (micro % 1000) + milliseconds++; + Sleep (milliseconds); + return 0; +#else unsigned int seconds = micro / 1000000; if (sizeof seconds < sizeof micro && micro / 1000000 != seconds) { @@ -50,9 +68,9 @@ usleep (useconds_t micro) seconds++; while ((seconds = sleep (seconds)) != 0); -#undef usleep -#if !HAVE_USLEEP -# define usleep(x) 0 -#endif +# if !HAVE_USLEEP +# define usleep(x) 0 +# endif return usleep (micro % 1000000); +#endif } -- cgit v1.2.3