delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2005/05/11/15:06:22

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Wed, 11 May 2005 22:01:49 +0300
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: gcc-patches AT gcc DOT gnu DOT org
Message-ID: <01c5565c$Blat.v2.4$082130a0@zahav.net.il>
X-Mailer: emacs 22.0.50 (via feedmail 8 I) and Blat ver 2.4
CC: gdb-patches AT sourceware DOT org, djgpp-workers AT delorie DOT com
Subject: RFA: fix libiberty/pex-djgpp.c
Reply-To: djgpp-workers AT delorie DOT com

The current CVS version of pex-djgpp.c didn't compile.  The patch
below fixes the problems I spotted; please review it.


2005-05-11  Eli Zaretskii  <eliz AT gnu DOT org>

	* pex-djgpp.c: Include string.h, fcntl.h, unistd.h, and
	sys/stat.h.
	(pex_init): Fix last argument to pex_init_common.
	(pex_djgpp_exec_child): Remove leading underscore from _open,
	_dup, _dup2, _close, and _spawnv/_spawnvp.  Replace `program',
	which is undeclared, with `executable', which was unused.  Remove
	unused variable `e'.  Fix casting of last arg to spawnv/spawnvp.
	(funcs): Add pex_djgpp_fdopenr.
	(pex_djgpp_fdopenr): New function; prototype added near the
	beginning.
	(pex_djgpp_wait): Declare arguments with ATTRIBUTE_UNUSED.

--- libiberty/pex-djgpp.c~0	2005-05-10 18:33:32.000000000 +0300
+++ libiberty/pex-djgpp.c	2005-05-11 21:53:20.000000000 +0300
@@ -29,6 +29,10 @@ extern int errno;
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
 #include <process.h>
 
 /* Use ECHILD if available, otherwise use EINVAL.  */
@@ -46,6 +50,7 @@ static long pex_djgpp_exec_child (struct
 static int pex_djgpp_close (struct pex_obj *, int);
 static int pex_djgpp_wait (struct pex_obj *, long, int *, struct pex_time *,
 			   int, const char **, int *);
+static FILE *pex_djgpp_fdopenr (struct pex_obj *, int, int);
 
 /* The list of functions we pass to the common routines.  */
 
@@ -57,7 +62,7 @@ const struct pex_funcs funcs =
   pex_djgpp_close,
   pex_djgpp_wait,
   NULL, /* pipe */
-  NULL, /* fdopenr */
+  pex_djgpp_fdopenr,
   NULL  /* cleanup */
 };
 
@@ -68,7 +73,7 @@ pex_init (int flags, const char *pname, 
 {
   /* DJGPP does not support pipes.  */
   flags &= ~ PEX_USE_PIPES;
-  return pex_init_common (flags, pname, tempbase, funcs);
+  return pex_init_common (flags, pname, tempbase, &funcs);
 }
 
 /* Open a file for reading.  */
@@ -119,46 +124,46 @@ pex_djgpp_exec_child (struct pex_obj *ob
 
   if (in != STDIN_FILE_NO)
     {
-      org_in = _dup (STDIN_FILE_NO);
+      org_in = dup (STDIN_FILE_NO);
       if (org_in < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup";
+	  *errmsg = "dup";
 	  return -1;
 	}
-      if (_dup2 (in, STDIN_FILE_NO) < 0)
+      if (dup2 (in, STDIN_FILE_NO) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup2";
+	  *errmsg = "dup2";
 	  return -1;
 	}
-      if (_close (in) < 0)
+      if (close (in) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_close";
+	  *errmsg = "close";
 	  return -1;
 	}
     }
 
   if (out != STDOUT_FILE_NO)
     {
-      org_out = _dup (STDOUT_FILE_NO);
+      org_out = dup (STDOUT_FILE_NO);
       if (org_out < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup";
+	  *errmsg = "dup";
 	  return -1;
 	}
-      if (_dup2 (out, STDOUT_FILE_NO) < 0)
+      if (dup2 (out, STDOUT_FILE_NO) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup2";
+	  *errmsg = "dup2";
 	  return -1;
 	}
-      if (_close (out) < 0)
+      if (close (out) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_close";
+	  *errmsg = "close";
 	  return -1;
 	}
     }
@@ -166,70 +171,68 @@ pex_djgpp_exec_child (struct pex_obj *ob
   if (errdes != STDERR_FILE_NO
       || (flags & PEX_STDERR_TO_STDOUT) != 0)
     {
-      int e;
-
-      org_errdes = _dup (STDERR_FILE_NO);
+      org_errdes = dup (STDERR_FILE_NO);
       if (org_errdes < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup";
+	  *errmsg = "dup";
 	  return -1;
 	}
-      if (_dup2 ((flags & PEX_STDERR_TO_STDOUT) != 0 ? STDOUT_FILE_NO : errdes,
+      if (dup2 ((flags & PEX_STDERR_TO_STDOUT) != 0 ? STDOUT_FILE_NO : errdes,
 		 STDERR_FILE_NO) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup2";
+	  *errmsg = "dup2";
 	  return -1;
 	}
       if (errdes != STDERR_FILE_NO)
 	{
-	  if (_close (errdes) < 0)
+	  if (close (errdes) < 0)
 	    {
 	      *err = errno;
-	      *errmsg = "_close";
+	      *errmsg = "close";
 	      return -1;
 	    }
 	}
     }
 
-  status = (((flags & PEX_SEARCH) != 0 ? _spawnvp : _spawnv)
-	    (P_WAIT, program, (const char **) argv));
+  status = (((flags & PEX_SEARCH) != 0 ? spawnvp : spawnv)
+	    (P_WAIT, executable, (char * const *) argv));
 
   if (status == -1)
     {
       *err = errno;
-      *errmsg = ((flags & PEX_SEARCH) != 0) ? "_spawnvp" : "_spawnv";
+      *errmsg = ((flags & PEX_SEARCH) != 0) ? "spawnvp" : "spawnv";
     }
 
   if (in != STDIN_FILE_NO)
     {
-      if (_dup2 (org_in, STDIN_FILE_NO) < 0)
+      if (dup2 (org_in, STDIN_FILE_NO) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup2";
+	  *errmsg = "dup2";
 	  return -1;
 	}
-      if (_close (org_in) < 0)
+      if (close (org_in) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_close";
+	  *errmsg = "close";
 	  return -1;
 	}
     }
 
   if (out != STDOUT_FILE_NO)
     {
-      if (_dup2 (org_out, STDOUT_FILE_NO) < 0)
+      if (dup2 (org_out, STDOUT_FILE_NO) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup2";
+	  *errmsg = "dup2";
 	  return -1;
 	}
-      if (_close (org_out) < 0)
+      if (close (org_out) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_close";
+	  *errmsg = "close";
 	  return -1;
 	}
     }
@@ -237,16 +240,16 @@ pex_djgpp_exec_child (struct pex_obj *ob
   if (errdes != STDERR_FILE_NO
       || (flags & PEX_STDERR_TO_STDOUT) != 0)
     {
-      if (_dup2 (org_errdes, STDERR_FILE_NO) < 0)
+      if (dup2 (org_errdes, STDERR_FILE_NO) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_dup2";
+	  *errmsg = "dup2";
 	  return -1;
 	}
-      if (_close (org_errdes) < 0)
+      if (close (org_errdes) < 0)
 	{
 	  *err = errno;
-	  *errmsg = "_close";
+	  *errmsg = "close";
 	  return -1;
 	}
     }
@@ -268,8 +271,9 @@ pex_djgpp_exec_child (struct pex_obj *ob
 
 static int
 pex_djgpp_wait (struct pex_obj *obj, long pid, int *status,
-		struct pex_time *time, int done, const char **errmsg,
-		int *err)
+		struct pex_time *time, int done ATTRIBUTE_UNUSED,
+		const char **errmsg ATTRIBUTE_UNUSED,
+		int *err ATTRIBUTE_UNUSED)
 {
   int *statuses;
 
@@ -281,3 +285,11 @@ pex_djgpp_wait (struct pex_obj *obj, lon
 
   return 0;
 }
+
+/* Get a FILE pointer to read from a file descriptor.  */
+
+static FILE *
+pex_djgpp_fdopenr (struct pex_obj *obj ATTRIBUTE_UNUSED, int fd, int binary)
+{
+  return fdopen (fd, (binary ? "rb" : "rt"));
+}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019