OSDN Git Service

Correct PR number in ChangeLogs.
[pf3gnuchains/gcc-fork.git] / fixincludes / fixincl.c
index a153a77..f8941c3 100644 (file)
@@ -18,21 +18,21 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include "fixlib.h"
 
 #include <sys/stat.h>
+#ifndef SEPARATE_FIX_PROC
+#include <sys/wait.h>
+#endif
 
 #if defined( HAVE_MMAP_FILE )
 #include <sys/mman.h>
 #define  BAD_ADDR ((void*)-1)
 #endif
 
-#if ! defined( SIGCHLD ) && defined( SIGCLD )
-#  define SIGCHLD SIGCLD
-#endif
 #ifndef SEPARATE_FIX_PROC
 #include "server.h"
 #endif
@@ -291,12 +291,8 @@ initialize ( int argc, char** argv )
 # endif
 
   signal (SIGQUIT, SIG_IGN);
-#ifdef SIGIOT
   signal (SIGIOT,  SIG_IGN);
-#endif
-#ifdef SIGPIPE
   signal (SIGPIPE, SIG_IGN);
-#endif
   signal (SIGALRM, SIG_IGN);
   signal (SIGTERM, SIG_IGN);
 }
@@ -458,7 +454,7 @@ run_compiles (void)
 {
   tFixDesc *p_fixd = fixDescList;
   int fix_ct = FIX_COUNT;
-  regex_t *p_re = xcalloc (REGEX_COUNT, sizeof (regex_t));
+  regex_t *p_re = XCNEWVEC (regex_t, REGEX_COUNT);
 
   /*  Make sure compile_re does not stumble across invalid data */
 
@@ -552,7 +548,11 @@ create_file (void)
           *pz_dir = NUL;
           if (stat (fname, &stbf) < 0)
             {
+#ifdef _WIN32
+              mkdir (fname);
+#else
               mkdir (fname, S_IFDIR | S_DIRALL);
+#endif
             }
 
           *pz_dir = '/';
@@ -835,8 +835,8 @@ internal_fix (int read_fd, tFixDesc* p_fixd)
    *  Make the fd passed in the stdin, and the write end of
    *  the new pipe become the stdout.
    */
-  fcntl (fd[1], F_DUPFD, STDOUT_FILENO);
-  fcntl (read_fd, F_DUPFD, STDIN_FILENO);
+  dup2 (fd[1], STDOUT_FILENO);
+  dup2 (read_fd, STDIN_FILENO);
 
   apply_fix (p_fixd, pz_curr_file);
   exit (0);
@@ -854,41 +854,43 @@ fix_with_system (tFixDesc* p_fixd,
   char*  pz_cmd;
   char*  pz_scan;
   size_t argsize;
-  int i;
-  tSCC z_applyfix_prog[2] = {
-    "/../fixincludes/applyfix" EXE_EXT,
-    "/../../fixincludes/applyfix" EXE_EXT };
 
   if (p_fixd->fd_flags & FD_SUBROUTINE)
-    for (i = 0; i < 2; i++)
-      { 
-       struct stat buf;
-
-        argsize = 32
-                + strlen( pz_orig_dir )
-                + sizeof( z_applyfix_prog )
-                + strlen( pz_fix_file )
-                + strlen( pz_file_source )
-                + strlen( pz_temp_file );
-
-        pz_cmd = xmalloc (argsize);
-
-        strcpy( pz_cmd, pz_orig_dir );
-        pz_scan = pz_cmd + strlen( pz_orig_dir );
-        strcpy( pz_scan, z_applyfix_prog );
-        pz_scan += sizeof( z_applyfix_prog ) - 1;
-
-       if (stat (pz_scan, &buf) != -1)
-         {
-            *(pz_scan++) = ' ';
-            /*
-             *  Now add the fix number and file names that may be needed
-             */
-            sprintf (pz_scan, "%ld \'%s\' \'%s\' \'%s\'", p_fixd - fixDescList,
-                    pz_fix_file, pz_file_source, pz_temp_file);
-           break;
-         }
-      }
+    {
+      static const char z_applyfix_prog[] =
+       "/../fixincludes/applyfix" EXE_EXT;
+
+      struct stat buf;
+      argsize = 32
+              + strlen (pz_orig_dir)
+              + sizeof (z_applyfix_prog)
+              + strlen (pz_fix_file)
+              + strlen (pz_file_source)
+              + strlen (pz_temp_file);
+
+      /* Allocate something sure to be big enough for our purposes */
+      pz_cmd = XNEWVEC (char, argsize);
+      strcpy (pz_cmd, pz_orig_dir);
+      pz_scan = pz_cmd + strlen (pz_orig_dir);
+
+      strcpy (pz_scan, z_applyfix_prog);
+
+      /* IF we can't find the "applyfix" executable file at the first guess,
+        try one level higher up  */
+      if (stat (pz_cmd, &buf) == -1)
+       {
+         strcpy (pz_scan, "/..");
+         strcpy (pz_scan+3, z_applyfix_prog);
+       }
+
+      pz_scan += strlen (pz_scan);
+
+      /*
+       *  Now add the fix number and file names that may be needed
+       */
+      sprintf (pz_scan, " %ld '%s' '%s' '%s'", p_fixd - fixDescList,
+              pz_fix_file, pz_file_source, pz_temp_file);
+    }
   else /* NOT an "internal" fix: */
     {
       size_t parg_size;
@@ -905,7 +907,7 @@ fix_with_system (tFixDesc* p_fixd,
          the following bizarre use of 'cat' only works on DOS boxes.
          It causes the file to be dropped into a temporary file for
          'cat' to read (pipes do not work on DOS).  */
-      tSCC   z_cmd_fmt[] = " \'%s\' | cat > \'%s\'";
+      tSCC   z_cmd_fmt[] = " '%s' | cat > '%s'";
 #else
       /* Don't use positional formatting arguments because some lame-o
          implementations cannot cope  :-(.  */
@@ -934,7 +936,7 @@ fix_with_system (tFixDesc* p_fixd,
         }
 
       /* Estimated buffer size we will need.  */
-      pz_scan = pz_cmd = xmalloc (argsize);
+      pz_scan = pz_cmd = XNEWVEC (char, argsize);
       /* How much of it do we allot to the program name and its
          arguments.  */
       parg_size = argsize - parg_size;
@@ -1021,7 +1023,7 @@ start_fixer (int read_fd, tFixDesc* p_fixd, char* pz_fix_file)
   else
     {
       tSCC z_cmd_fmt[] = "file='%s'\n%s";
-      pz_cmd = xmalloc (strlen (p_fixd->patch_args[2])
+      pz_cmd = XNEWVEC (char, strlen (p_fixd->patch_args[2])
                        + sizeof (z_cmd_fmt) + strlen (pz_fix_file));
       sprintf (pz_cmd, z_cmd_fmt, pz_fix_file, p_fixd->patch_args[2]);
       pz_cmd_save = p_fixd->patch_args[2];
@@ -1200,7 +1202,10 @@ write_replacement (tFixDesc* p_fixd)
 
    {
      FILE* out_fp = create_file ();
-     fputs (pz_text, out_fp);
+     size_t sz = strlen (pz_text);
+     fwrite (pz_text, sz, 1, out_fp);
+     if (pz_text[ sz-1 ] != '\n')
+       fputc ('\n', out_fp);
      fclose (out_fp);
    }
 }