changeset 13742:886a8812ecd0

New module 'waitpid'. * lib/waitpid.c: New file, extracted from lib/sys_wait.in.h. * lib/sys_wait.in.h: Include <sys/types.h>, c++defs.h, warn-on-use.h. Don't include <process.h>. (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 <tmacchant5@yahoo.co.jp>.
author Bruno Haible <bruno@clisp.org>
date Wed, 29 Sep 2010 13:17:43 +0200
parents b079c369732b
children ebf34d732f15
files ChangeLog lib/sys_wait.in.h lib/waitpid.c m4/sys_wait_h.m4 m4/waitpid.m4 modules/sys_wait modules/waitpid
diffstat 7 files changed, 128 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-29  Bruno Haible  <bruno@clisp.org>
+
+	New module 'waitpid'.
+	* lib/waitpid.c: New file, extracted from lib/sys_wait.in.h.
+	* lib/sys_wait.in.h: Include <sys/types.h>, c++defs.h, warn-on-use.h.
+	Don't include <process.h>.
+	(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 <tmacchant5@yahoo.co.jp>.
+
 2010-09-28  Bruno Haible  <bruno@clisp.org>
 
 	poll: Assume ANSI C.
--- 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 <sys/types.h>
+
+
+/* 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 <process.h> /* for _cwait, WAIT_CHILD */
 # include <signal.h> /* 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 */
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 <config.h>
+
+/* Specification.  */
+#include <sys/wait.h>
+
+/* Implementation for native Win32 systems.  */
+
+#include <process.h> /* for _cwait, WAIT_CHILD */
+
+pid_t
+waitpid (pid_t pid, int *statusp, int options)
+{
+  return _cwait (statusp, pid, WAIT_CHILD);
+}
--- 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 <sys/wait.h> 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 <sys/wait.h>]],
+    [waitpid])
 ])
 
 AC_DEFUN([gl_SYS_WAIT_MODULE_INDICATOR],
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
+])
--- 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 <sys/wait.h> 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 $@
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:
+<sys/wait.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Bruno Haible