OSDN Git Service

PR driver/40144
[pf3gnuchains/gcc-fork.git] / libiberty / pex-unix.c
index 91619af..366e96e 100644 (file)
@@ -269,11 +269,12 @@ static void pex_child_error (struct pex_obj *, const char *, const char *, int)
      ATTRIBUTE_NORETURN;
 static int pex_unix_open_read (struct pex_obj *, const char *, int);
 static int pex_unix_open_write (struct pex_obj *, const char *, int);
-static long pex_unix_exec_child (struct pex_obj *, int, const char *,
+static pid_t pex_unix_exec_child (struct pex_obj *, int, const char *,
                                 char * const *, char * const *,
-                                 int, int, int, const char **, int *);
+                                int, int, int, int,
+                                const char **, int *);
 static int pex_unix_close (struct pex_obj *, int);
-static int pex_unix_wait (struct pex_obj *, long, int *, struct pex_time *,
+static int pex_unix_wait (struct pex_obj *, pid_t, int *, struct pex_time *,
                          int, const char **, int *);
 static int pex_unix_pipe (struct pex_obj *, int *, int);
 static FILE *pex_unix_fdopenr (struct pex_obj *, int, int);
@@ -338,7 +339,7 @@ static void
 pex_child_error (struct pex_obj *obj, const char *executable,
                 const char *errmsg, int err)
 {
-#define writeerr(s) write (STDERR_FILE_NO, s, strlen (s))
+#define writeerr(s) (void) write (STDERR_FILE_NO, s, strlen (s))
   writeerr (obj->pname);
   writeerr (": error trying to exec '");
   writeerr (executable);
@@ -354,11 +355,11 @@ pex_child_error (struct pex_obj *obj, const char *executable,
 
 extern char **environ;
 
-static long
+static pid_t
 pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
                     char * const * argv, char * const * env,
                      int in, int out, int errdes,
-                    const char **errmsg, int *err)
+                    int toclose, const char **errmsg, int *err)
 {
   pid_t pid;
 
@@ -383,7 +384,7 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
     case -1:
       *err = errno;
       *errmsg = VFORK_STRING;
-      return -1;
+      return (pid_t) -1;
 
     case 0:
       /* Child process.  */
@@ -408,6 +409,11 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
          if (close (errdes) < 0)
            pex_child_error (obj, executable, "close", errno);
        }
+      if (toclose >= 0)
+       {
+         if (close (toclose) < 0)
+           pex_child_error (obj, executable, "close", errno);
+       }
       if ((flags & PEX_STDERR_TO_STDOUT) != 0)
        {
          if (dup2 (STDOUT_FILE_NO, STDERR_FILE_NO) < 0)
@@ -415,7 +421,7 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
        }
 
       if (env)
-        environ = env;
+        environ = (char**) env;
 
       if ((flags & PEX_SEARCH) != 0)
        {
@@ -429,7 +435,7 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
        }
 
       /* NOTREACHED */
-      return -1;
+      return (pid_t) -1;
 
     default:
       /* Parent process.  */
@@ -439,7 +445,7 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
            {
              *err = errno;
              *errmsg = "close";
-             return -1;
+             return (pid_t) -1;
            }
        }
       if (out != STDOUT_FILE_NO)
@@ -448,7 +454,7 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
            {
              *err = errno;
              *errmsg = "close";
-             return -1;
+             return (pid_t) -1;
            }
        }
       if (errdes != STDERR_FILE_NO)
@@ -457,18 +463,18 @@ pex_unix_exec_child (struct pex_obj *obj, int flags, const char *executable,
            {
              *err = errno;
              *errmsg = "close";
-             return -1;
+             return (pid_t) -1;
            }
        }
 
-      return (long) pid;
+      return pid;
     }
 }
 
 /* Wait for a child process to complete.  */
 
 static int
-pex_unix_wait (struct pex_obj *obj, long pid, int *status,
+pex_unix_wait (struct pex_obj *obj, pid_t pid, int *status,
               struct pex_time *time, int done, const char **errmsg,
               int *err)
 {