From 6a43884b2d4737bd78949becf8de806f102ff6d8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 1 May 2007 22:15:01 +0000 Subject: [PATCH] New module 'sleep'. --- ChangeLog | 11 +++++++++++ doc/functions/sleep.texi | 5 ++++- lib/sleep.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ lib/unistd_.h | 17 +++++++++++++++++ m4/sleep.m4 | 19 +++++++++++++++++++ m4/unistd_h.m4 | 4 +++- modules/sleep | 25 +++++++++++++++++++++++++ modules/unistd | 2 ++ 8 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 lib/sleep.c create mode 100644 m4/sleep.m4 create mode 100644 modules/sleep diff --git a/ChangeLog b/ChangeLog index a1267f15a..c19ef30dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2007-05-01 Bruno Haible + * 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 + * lib/sigprocmask.h: Remove file. * lib/signal_.h: Incorporate the previous contents of sigprocmask.h. * lib/sigprocmask.c: Include instead of sigprocmask.h. diff --git a/doc/functions/sleep.texi b/doc/functions/sleep.texi index d0781fd80..eaf2196f9 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 000000000..037559b01 --- /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 , 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 + +/* Specification. */ +#include + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +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 4febc90b4..9beffce1f 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 + . */ +# 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 000000000..2c9d75cd6 --- /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 628b81868..d62da6953 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 000000000..13c20f072 --- /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: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/unistd b/modules/unistd index 5108617e8..58a6c21dc 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' \ -- 2.11.0