summaryrefslogtreecommitdiff
path: root/tests/usleep.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-01-08 11:51:07 +0100
committerJörg Frings-Fürst <debian@jff.email>2022-01-08 11:51:07 +0100
commitbe8efac78d067c138ad8dda03df4336e73f94887 (patch)
tree5f5254a628ba0ef72065b93d949d1c985742ea8e /tests/usleep.c
parent7b65dbd4ebade81d504cfe5e681292a58ad1fdf0 (diff)
New upstream version 1.0upstream/1.0
Diffstat (limited to 'tests/usleep.c')
-rw-r--r--tests/usleep.c42
1 files changed, 30 insertions, 12 deletions
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 <ebb9@byu.net>, 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 <https://www.gnu.org/licenses/>. */
/* This file is _intentionally_ light-weight. Rather than using
@@ -28,6 +28,11 @@
#include <errno.h>
+#if defined _WIN32 && ! defined __CYGWIN__
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+#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
}