summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-09-29 13:17:43 +0200
committerBruno Haible <bruno@clisp.org>2010-09-29 13:17:43 +0200
commit3215ba10fd6dcff44bb0f6748b161f56dcd28d01 (patch)
treee27b6bac1e910cb82f1794359744589dae261ff7
parent89c936487278c4567c724b3ec826873f46f72c5a (diff)
downloadgnulib-3215ba10fd6dcff44bb0f6748b161f56dcd28d01.tar.gz
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>.
-rw-r--r--ChangeLog14
-rw-r--r--lib/sys_wait.in.h46
-rw-r--r--lib/waitpid.c31
-rw-r--r--m4/sys_wait_h.m47
-rw-r--r--m4/waitpid.m415
-rw-r--r--modules/sys_wait7
-rw-r--r--modules/waitpid23
7 files changed, 128 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index d1553caf63..6ca044488d 100644
--- 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.
diff --git a/lib/sys_wait.in.h b/lib/sys_wait.in.h
index 0006112ead..6f0ef3687d 100644
--- 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 @@ extern "C" {
#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
index 0000000000..6db275390b
--- /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);
+}
diff --git a/m4/sys_wait_h.m4 b/m4/sys_wait_h.m4
index b0d23fac75..dd44581d55 100644
--- 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 @@ AC_DEFUN([gl_SYS_WAIT_H],
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],
diff --git a/m4/waitpid.m4 b/m4/waitpid.m4
new file mode 100644
index 0000000000..887d9fe5d5
--- /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
index 376b08c2c8..2c82029711 100644
--- a/modules/sys_wait
+++ b/modules/sys_wait
@@ -6,7 +6,10 @@ lib/sys_wait.in.h
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 @@ BUILT_SOURCES += sys/wait.h
# 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 $@
diff --git a/modules/waitpid b/modules/waitpid
new file mode 100644
index 0000000000..f8fbf0f761
--- /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