# HG changeset patch # User Bruno Haible # Date 1285759063 -7200 # Node ID 886a8812ecd0421ad0a8bb11d70d53036a69ab9a # Parent b079c369732b8a5e4e6feed4c64b6fc6ae3f52f7 New module 'waitpid'. * lib/waitpid.c: New file, extracted from lib/sys_wait.in.h. * lib/sys_wait.in.h: Include , c++defs.h, warn-on-use.h. Don't include . (waitpid): Declare only, using modern idiom. * m4/waitpid.m4: New file. * m4/sys_wait_h.m4 (gl_SYS_WAIT_H): Check whether waitpid is declared. * modules/waitpid: New file. * modules/sys_wait (Depends-on): Add c++defs, warn-on-use, waitpid. (Makefile.am): Update. Reported by Tatsuro MATSUOKA . diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-09-29 Bruno Haible + + New module 'waitpid'. + * lib/waitpid.c: New file, extracted from lib/sys_wait.in.h. + * lib/sys_wait.in.h: Include , c++defs.h, warn-on-use.h. + Don't include . + (waitpid): Declare only, using modern idiom. + * m4/waitpid.m4: New file. + * m4/sys_wait_h.m4 (gl_SYS_WAIT_H): Check whether waitpid is declared. + * modules/waitpid: New file. + * modules/sys_wait (Depends-on): Add c++defs, warn-on-use, waitpid. + (Makefile.am): Update. + Reported by Tatsuro MATSUOKA . + 2010-09-28 Bruno Haible poll: Assume ANSI C. diff --git a/lib/sys_wait.in.h b/lib/sys_wait.in.h --- a/lib/sys_wait.in.h +++ b/lib/sys_wait.in.h @@ -30,6 +30,15 @@ #ifndef _GL_SYS_WAIT_H #define _GL_SYS_WAIT_H +/* Get pid_t. */ +#include + + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + #if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) /* Unix API. */ @@ -71,24 +80,11 @@ # define WCOREDUMP(x) ((x) & 0x80) # endif -# ifdef __cplusplus -extern "C" { -# endif - -/* Declarations of functions. */ - -# ifdef __cplusplus -} -# endif - #else /* Native Windows API. */ -# include /* for _cwait, WAIT_CHILD */ # include /* for SIGTERM */ -# define waitpid(pid,statusp,options) _cwait (statusp, pid, WAIT_CHILD) - /* The following macros apply to an argument x, that is a status of a process, as returned by waitpid() or, equivalently, _cwait() or GetExitCodeProcess(). This value is simply an 'int', not composed of bit fields. */ @@ -111,5 +107,29 @@ #endif +#ifdef __cplusplus +extern "C" { +#endif + +/* Declarations of functions. */ + +#if 1 /* @GNULIB_WAITPID@ */ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +_GL_FUNCDECL_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options)); +# endif +_GL_CXXALIAS_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options)); +_GL_CXXALIASWARN (waitpid); +#elif defined GNULIB_POSIXCHECK +# undef waitpid +# if HAVE_RAW_DECL_WAITPID +_GL_WARN_ON_USE (waitpid, "waitpid is unportable - " + "use gnulib module sys_wait for portability"); +# endif +#endif + +#ifdef __cplusplus +} +#endif + #endif /* _GL_SYS_WAIT_H */ #endif /* _GL_SYS_WAIT_H */ diff --git a/lib/waitpid.c b/lib/waitpid.c new file mode 100644 --- /dev/null +++ b/lib/waitpid.c @@ -0,0 +1,31 @@ +/* Wait for process state change. + Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc. + + 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 + +/* Implementation for native Win32 systems. */ + +#include /* for _cwait, WAIT_CHILD */ + +pid_t +waitpid (pid_t pid, int *statusp, int options) +{ + return _cwait (statusp, pid, WAIT_CHILD); +} diff --git a/m4/sys_wait_h.m4 b/m4/sys_wait_h.m4 --- a/m4/sys_wait_h.m4 +++ b/m4/sys_wait_h.m4 @@ -1,4 +1,4 @@ -# sys_wait_h.m4 serial 4 +# sys_wait_h.m4 serial 5 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,6 +10,11 @@ dnl is always overridden, because of GNULIB_POSIXCHECK. gl_CHECK_NEXT_HEADERS([sys/wait.h]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[#include ]], + [waitpid]) ]) AC_DEFUN([gl_SYS_WAIT_MODULE_INDICATOR], diff --git a/m4/waitpid.m4 b/m4/waitpid.m4 new file mode 100644 --- /dev/null +++ b/m4/waitpid.m4 @@ -0,0 +1,15 @@ +# waitpid.m4 serial 1 +dnl Copyright (C) 2010 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_WAITPID], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + case $host_os in + mingw*) + AC_LIBOBJ([waitpid]) + ;; + esac +]) diff --git a/modules/sys_wait b/modules/sys_wait --- a/modules/sys_wait +++ b/modules/sys_wait @@ -6,7 +6,10 @@ m4/sys_wait_h.m4 Depends-on: +c++defs include_next +warn-on-use +waitpid configure.ac: gl_SYS_WAIT_H @@ -17,13 +20,15 @@ # We need the following in order to create when the system # has one that is incomplete. -sys/wait.h: sys_wait.in.h +sys/wait.h: sys_wait.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_SYS_WAIT_H''@|$(NEXT_SYS_WAIT_H)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/sys_wait.in.h; \ } > $@-t && \ mv $@-t $@ diff --git a/modules/waitpid b/modules/waitpid new file mode 100644 --- /dev/null +++ b/modules/waitpid @@ -0,0 +1,23 @@ +Description: +waitpid() function: wait for process state change + +Files: +lib/waitpid.c +m4/waitpid.m4 + +Depends-on: +sys_wait + +configure.ac: +gl_FUNC_WAITPID + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +Bruno Haible