* ld-scripts/script.t: Put .pr in .text, and .rw in .data, for
[deliverable/binutils-gdb.git] / binutils / objcopy.c
index 0ef9cebcdee2f43aa9f8bb23427b87361fd18147..befe5093491427a00a6ba4a2ab0e77d79712ba39 100644 (file)
@@ -15,7 +15,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 \f
 #include "bfd.h"
 #include "sysdep.h"
@@ -746,7 +746,7 @@ copy_object (ibfd, obfd)
       if (max_gap > 8192)
        max_gap = 8192;
       buf = (bfd_byte *) xmalloc (max_gap);
-      memset (buf, gap_fill, max_gap);
+      memset (buf, gap_fill, (size_t) max_gap);
 
       c = bfd_count_sections (obfd);
       for (i = 0; i < c; i++)
@@ -1253,6 +1253,9 @@ mark_symbols_used_in_relocations (ibfd, isection, symbolsarg)
   if (relsize < 0)
     bfd_fatal (bfd_get_filename (ibfd));
 
+  if (relsize == 0)
+    return 0;
+
   relpp = (arelent **) xmalloc (relsize);
   relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, symbols);
   if (relcount < 0)
@@ -1283,6 +1286,7 @@ simple_copy (from, to)
      char *from, *to;
 {
   int fromfd, tofd, nread;
+  int saved;
   char buf[COPY_BUF];
 
   fromfd = open (from, O_RDONLY);
@@ -1291,22 +1295,30 @@ simple_copy (from, to)
   tofd = open (to, O_WRONLY | O_CREAT | O_TRUNC);
   if (tofd < 0)
     {
+      saved = errno;
       close (fromfd);
+      errno = saved;
       return -1;
     }
   while ((nread = read (fromfd, buf, sizeof buf)) > 0)
     {
       if (write (tofd, buf, nread) != nread)
        {
+         saved = errno;
          close (fromfd);
          close (tofd);
+         errno = saved;
          return -1;
        }
     }
+  saved = errno;
   close (fromfd);
   close (tofd);
   if (nread < 0)
-    return -1;
+    {
+      errno = saved;
+      return -1;
+    }
   return 0;
 }
 
@@ -1348,7 +1360,7 @@ smart_rename (from, to)
        {
          /* We have to clean up here. */
          int saved = errno;
-         fprintf (stderr, "%s: `%s': ", program_name, to);
+         fprintf (stderr, "%s: %s: ", program_name, to);
          errno = saved;
          perror ("rename");
          unlink (from);
@@ -1357,8 +1369,14 @@ smart_rename (from, to)
   else
     {
       ret = simple_copy (from, to);
-      if (ret == 0)
-       unlink (from);
+      if (ret != 0)
+       {
+         int saved = errno;
+         fprintf (stderr, "%s: %s: ", program_name, to);
+         errno = saved;
+         perror ("simple_copy");
+       }
+      unlink (from);
     }
   return ret;
 }
This page took 0.024338 seconds and 4 git commands to generate.