]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
adaint.h, adaint.c (__gnat_waitpid): Moved to expect.c where it is used.
authorPascal Obry <obry@adacore.com>
Fri, 18 Mar 2005 11:46:57 +0000 (12:46 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Fri, 18 Mar 2005 11:46:57 +0000 (12:46 +0100)
2005-03-17  Pascal Obry  <obry@adacore.com>

* adaint.h, adaint.c (__gnat_waitpid): Moved to expect.c where it is
used.

* expect.c (__gnat_waitpid): Moved here from adaint.c.
Reimplement under Win32 using Win32 API.
(__gnat_kill) [Win32]: Properly close the process handle before leaving
this routine.

From-SVN: r96659

gcc/ada/adaint.c
gcc/ada/adaint.h
gcc/ada/expect.c

index 73be5e1a8cb6a17fe22c7f30bf8d8549f2569406..cbe96f40a8baef39515b46678453f892344d77be 100644 (file)
@@ -1927,23 +1927,6 @@ __gnat_portable_wait (int *process_status)
   return pid;
 }
 
-int
-__gnat_waitpid (int pid)
-{
-  int status = 0;
-
-#if defined (_WIN32)
-  cwait (&status, pid, _WAIT_CHILD);
-#elif defined (__EMX__) || defined (MSDOS) || defined (__vxworks)
-  /* Status is already zero, so nothing to do.  */
-#else
-  waitpid (pid, &status, 0);
-  status =  WEXITSTATUS (status);
-#endif
-
-  return status;
-}
-
 void
 __gnat_os_exit (int status)
 {
index cf7e4032f4ad6096c19fe55b52d4d782f18baf4f..97d913bf99647e1b05e23d0568d1fdc2c273587c 100644 (file)
@@ -93,7 +93,6 @@ extern int    __gnat_is_symbolic_link            (char *name);
 extern int    __gnat_portable_spawn                (char *[]);
 extern int    __gnat_portable_no_block_spawn       (char *[]);
 extern int    __gnat_portable_wait                 (int *);
-extern int    __gnat_waitpid                      (int);
 extern char  *__gnat_locate_exec                   (char *, char *);
 extern char  *__gnat_locate_exec_on_path          (char *);
 extern char  *__gnat_locate_regular_file           (char *, char *);
index f0b4bfb9db70fe8b2b9789a466b093e4330ffce3..dcb6776842e8fd5ad33ea16a6fc802287c1d9b18 100644 (file)
 #include "system.h"
 #endif
 
+#include <sys/types.h>
+
+#ifdef __MINGW32__
+#if OLD_MINGW
+#include <sys/wait.h>
+#endif
+#else
+#include <sys/wait.h>
+#endif
+
 /* This file provides the low level functionalities needed to implement Expect
    capabilities in GNAT.Expect.
    Implementations for unix and windows systems is provided.
@@ -72,10 +82,32 @@ __gnat_kill (int pid, int sig)
     {
       process_handle = OpenProcess (PROCESS_TERMINATE, FALSE, pid);
       if (process_handle != NULL)
-       TerminateProcess (process_handle, 0);
+       {
+         TerminateProcess (process_handle, 0);
+         CloseHandle (process_handle);
+       }
     }
 }
 
+int
+__gnat_waitpid (int pid)
+{
+  HANDLE process_handle;
+  DWORD exitcode = 1;
+  DWORD res;
+
+  process_handle = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);
+
+  if (process_handle != NULL)
+    {
+      res = WaitForSingleObject (process_handle, INFINITE);
+      GetExitCodeProcess (process_handle, &exitcode);
+      CloseHandle (process_handle);
+    }
+
+  return (int) exitcode;
+}
+
 int
 __gnat_expect_fork (void)
 {
@@ -157,6 +189,17 @@ __gnat_expect_poll (int *fd, int num_fd, int timeout, int *is_set)
 #include <vms/stsdef.h>
 #include <vms/iodef.h>
 
+int
+__gnat_waitpid (int pid)
+{
+  int status = 0;
+
+  waitpid (pid, &status, 0);
+  status =  WEXITSTATUS (status);
+
+  return status;
+}
+
 int
 __gnat_pipe (int *fd)
 {
@@ -297,6 +340,17 @@ __gnat_kill (int pid, int sig)
   kill (pid, sig);
 }
 
+int
+__gnat_waitpid (int pid)
+{
+  int status = 0;
+
+  waitpid (pid, &status, 0);
+  status =  WEXITSTATUS (status);
+
+  return status;
+}
+
 int
 __gnat_pipe (int *fd)
 {
@@ -404,6 +458,12 @@ __gnat_kill (int pid, int sig)
 {
 }
 
+int
+__gnat_waitpid (int pid, int sig)
+{
+  return 0;
+}
+
 int
 __gnat_pipe (int *fd)
 {