bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'sleep'


From: Bruno Haible
Subject: new module 'sleep'
Date: Wed, 2 May 2007 00:14:13 +0200
User-agent: KMail/1.5.4

The function sleep() is missing on mingw 2005 (although it was present in some
older versions of mingw). This provides a substitute.

2007-05-01  Bruno Haible  <address@hidden>

        * 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.

============================ modules/sleep =================================
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

============================= lib/sleep.c ==================================
/* Pausing execution of the current thread.
   Copyright (C) 2007 Free Software Foundation, Inc.
   Written by Bruno Haible <address@hidden>, 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
============================= m4/sleep.m4 ==================================
# 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], [:])
============================================================================
*** doc/functions/sleep.texi    1 May 2007 15:11:39 -0000       1.1
--- doc/functions/sleep.texi    1 May 2007 22:07:32 -0000
***************
*** 4,13 ****
  
  POSIX specification: @url{http://www.opengroup.org/susv3xsh/sleep.html}
  
! Gnulib module: ---
  
  Portability problems fixed by Gnulib:
  @itemize
  @end itemize
  
  Portability problems not fixed by Gnulib:
--- 4,16 ----
  
  POSIX specification: @url{http://www.opengroup.org/susv3xsh/sleep.html}
  
! 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:
*** lib/unistd_.h       27 Apr 2007 17:14:40 -0000      1.6
--- lib/unistd_.h       1 May 2007 22:07:32 -0000
***************
*** 191,196 ****
--- 191,213 ----
  #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 address@hidden@
+ 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
*** m4/unistd_h.m4      19 Feb 2007 02:24:42 -0000      1.5
--- m4/unistd_h.m4      1 May 2007 22:07:32 -0000
***************
*** 1,4 ****
! # unistd_h.m4 serial 5
  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,
--- 1,4 ----
! # 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,49 ****
--- 40,51 ----
    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])
*** modules/unistd      19 Feb 2007 02:24:42 -0000      1.7
--- modules/unistd      1 May 2007 22:07:32 -0000
***************
*** 29,37 ****
--- 29,39 ----
              -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' \





reply via email to

[Prev in Thread] Current Thread [Next in Thread]