From ca21b4a51c8e1c6f6f36188dd82be0596ba1722f Mon Sep 17 00:00:00 2001
From: Bruce Korb <bkorb@gnu.org>
Date: Tue, 6 Feb 2001 22:19:50 +0000
Subject: [PATCH] do not rely on load_file_data() to close file pointer

From-SVN: r39501
---
 gcc/ChangeLog           |  7 +++++++
 gcc/fixinc/fixincl.c    | 14 +++++++-------
 gcc/fixinc/fixlib.c     |  5 +++--
 gcc/fixinc/inclhack.def |  1 +
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6273b2ae5a4d..0937f2473b01 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2001-01-30  Bruce Korb  <bkorb@gnu.org>
+
+        fixinc/fixincl.c(process):  Emit error message only if appropriate :)
+        (load_file): do not rely on load_file_data() to close file pointer
+        fixinc/fixlib.c(load_file_data): do not close passed in file pointer
+	fixinc/inclhack.def(irix_limits_const): add test_text
+
 2001-02-06  Neil Booth  <neil@daikokuya.demon.co.uk>
 
         * cppexp.c (parse_defined): Improve diagnostics for invalid
diff --git a/gcc/fixinc/fixincl.c b/gcc/fixinc/fixincl.c
index 3f2cb564e7c2..bd134255b8f5 100644
--- a/gcc/fixinc/fixincl.c
+++ b/gcc/fixinc/fixincl.c
@@ -364,14 +364,13 @@ load_file ( fname )
     res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ,
                        MAP_PRIVATE, data_map_fd, 0);
   if (res == (char*)BAD_ADDR)
+#endif
     {
+      FILE* fp = fdopen (data_map_fd, "r");
       curr_data_mapped = BOOL_FALSE;
-      res = load_file_data ( fdopen (data_map_fd, "r"));
+      res = load_file_data (fp);
+      fclose (fp);
     }
-#else
-  curr_data_mapped = BOOL_FALSE;
-  res = load_file_data ( fdopen (data_map_fd, "r"));
-#endif
 
   return res;
 }
@@ -1431,8 +1430,9 @@ process ()
   read_fd = open (pz_temp_file, O_RDONLY);
   if (read_fd < 0)
     {
-      fprintf (stderr, "error %d (%s) opening output (%s) for read\n",
-               errno, xstrerror (errno), pz_temp_file);
+      if (errno != ENOENT)
+        fprintf (stderr, "error %d (%s) opening output (%s) for read\n",
+                 errno, xstrerror (errno), pz_temp_file);
     }
   else
     {
diff --git a/gcc/fixinc/fixlib.c b/gcc/fixinc/fixlib.c
index 7bf8cbcb957f..647d2b379686 100644
--- a/gcc/fixinc/fixlib.c
+++ b/gcc/fixinc/fixlib.c
@@ -39,6 +39,9 @@ load_file_data (fp)
   int    space_left = -1;  /* allow for terminating NUL */
   size_t space_used = 0;
 
+  if (fp == (FILE*)NULL)
+    return pz_data;
+
   do
     {
       size_t  size_read;
@@ -62,7 +65,6 @@ load_file_data (fp)
                 fprintf (stderr, "error %d (%s) reading input\n", err,
                          xstrerror (err));
               free ((void *) pz_data);
-              fclose (fp);
               return (char *) NULL;
             }
         }
@@ -73,7 +75,6 @@ load_file_data (fp)
 
   pz_data = xrealloc ((void*)pz_data, space_used+1 );
   pz_data[ space_used ] = NUL;
-  fclose (fp);
 
   return pz_data;
 }
diff --git a/gcc/fixinc/inclhack.def b/gcc/fixinc/inclhack.def
index 860ec37848c0..40332750c1df 100644
--- a/gcc/fixinc/inclhack.def
+++ b/gcc/fixinc/inclhack.def
@@ -1292,6 +1292,7 @@ fix = {
     select	= "^extern const ";
     c_fix	= format;
     c_fix_arg	= "extern __const ";
+    test_text   = "extern const char limit; /* test\n\tlimits */";
 };
 
 
-- 
GitLab