summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-05-01 22:15:01 +0000
committerBruno Haible <bruno@clisp.org>2007-05-01 22:15:01 +0000
commit6a43884b2d4737bd78949becf8de806f102ff6d8 (patch)
treed5590dc9e45865e704ed59d0e2d774f00469df5b
parent3ab16f027a71fbdc4b234295e6da9e9781da0da7 (diff)
downloadgnulib-6a43884b2d4737bd78949becf8de806f102ff6d8.tar.gz
New module 'sleep'.
-rw-r--r--ChangeLog11
-rw-r--r--doc/functions/sleep.texi5
-rw-r--r--lib/sleep.c47
-rw-r--r--lib/unistd_.h17
-rw-r--r--m4/sleep.m419
-rw-r--r--m4/unistd_h.m44
-rw-r--r--modules/sleep25
-rw-r--r--modules/unistd2
8 files changed, 128 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a1267f15a5..c19ef30dc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2007-05-01 Bruno Haible <bruno@clisp.org>
+ * modules/sleep: New file.
+ * lib/sleep.c: New file.
+ * m4/sleep.m4: New file.
+ * lib/unistd_.h (sleep): New declaration.
+ * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_SLEEP,
+ HAVE_SLEEP.
+ * modules/unistd (Makefile.am): Substitute GNULIB_SLEEP, HAVE_SLEEP.
+ * doc/functions/sleep.texi: Document the sleep module.
+
+2007-05-01 Bruno Haible <bruno@clisp.org>
+
* lib/sigprocmask.h: Remove file.
* lib/signal_.h: Incorporate the previous contents of sigprocmask.h.
* lib/sigprocmask.c: Include <signal.h> instead of sigprocmask.h.
diff --git a/doc/functions/sleep.texi b/doc/functions/sleep.texi
index d0781fd803..eaf2196f95 100644
--- a/doc/functions/sleep.texi
+++ b/doc/functions/sleep.texi
@@ -4,10 +4,13 @@
POSIX specification: @url{http://www.opengroup.org/susv3xsh/sleep.html}
-Gnulib module: ---
+Gnulib module: sleep
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+mingw (2005 or newer).
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/lib/sleep.c b/lib/sleep.c
new file mode 100644
index 0000000000..037559b016
--- /dev/null
+++ b/lib/sleep.c
@@ -0,0 +1,47 @@
+/* Pausing execution of the current thread.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2007.
+
+ 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 2, or (at your option)
+ any later version.
+
+ This program 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+
+unsigned int
+sleep (unsigned int seconds)
+{
+ unsigned int remaining;
+
+ /* Sleep for 1 second many times, because
+ 1. Sleep is not interruptiple by Ctrl-C,
+ 2. we want to avoid arithmetic overflow while multiplying with 1000. */
+ for (remaining = seconds; remaining > 0; remaining--)
+ Sleep (1000);
+
+ return remaining;
+}
+
+#else
+
+ #error "Please port gnulib sleep.c to your platform, possibly using usleep() or select(), then report this to bug-gnulib."
+
+#endif
diff --git a/lib/unistd_.h b/lib/unistd_.h
index 4febc90b46..9beffce1fc 100644
--- a/lib/unistd_.h
+++ b/lib/unistd_.h
@@ -191,6 +191,23 @@ extern int readlink (const char *file, char *buf, size_t bufsize);
#endif
+#if @GNULIB_SLEEP@
+/* Pause the execution of the current thread for N seconds.
+ Returns the number of seconds left to sleep.
+ See the POSIX:2001 specification
+ <http://www.opengroup.org/susv3xsh/sleep.html>. */
+# if !@HAVE_SLEEP@
+extern unsigned int sleep (unsigned int n);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef sleep
+# define sleep(n) \
+ (GL_LINK_WARNING ("sleep is unportable - " \
+ "use gnulib module sleep for portability"), \
+ sleep (n))
+#endif
+
+
#ifdef __cplusplus
}
#endif
diff --git a/m4/sleep.m4 b/m4/sleep.m4
new file mode 100644
index 0000000000..2c9d75cd6f
--- /dev/null
+++ b/m4/sleep.m4
@@ -0,0 +1,19 @@
+# sleep.m4 serial 1
+dnl Copyright (C) 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_SLEEP],
+[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_CHECK_FUNCS_ONCE([sleep])
+ if test $ac_cv_func_sleep = no; then
+ HAVE_SLEEP=0
+ AC_LIBOBJ([sleep])
+ gl_PREREQ_SLEEP
+ fi
+])
+
+# Prerequisites of lib/sleep.c.
+AC_DEFUN([gl_PREREQ_SLEEP], [:])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index 628b818683..d62da6953d 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 5
+# unistd_h.m4 serial 6
dnl Copyright (C) 2006-2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -40,10 +40,12 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK])
+ GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
+ HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP])
HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR])
diff --git a/modules/sleep b/modules/sleep
new file mode 100644
index 0000000000..13c20f0721
--- /dev/null
+++ b/modules/sleep
@@ -0,0 +1,25 @@
+Description:
+sleep() function: pause execution of the current thread.
+
+Files:
+lib/sleep.c
+m4/sleep.m4
+
+Depends-on:
+unistd
+
+configure.ac:
+gl_FUNC_SLEEP
+gl_UNISTD_MODULE_INDICATOR([sleep])
+
+Makefile.am:
+
+Include:
+<unistd.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
diff --git a/modules/unistd b/modules/unistd
index 5108617e81..58a6c21dc7 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -29,9 +29,11 @@ unistd.h: unistd_.h
-e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
-e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
-e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
+ -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
-e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
-e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
-e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
+ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
-e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
-e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
-e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \