bfd/
[deliverable/binutils-gdb.git] / binutils / ar.c
index e48249e3245cce1ffbe74c9109c3f014735af0f7..720ced73e9828c269f5302a8e777150bc2c6545e 100644 (file)
@@ -1,6 +1,6 @@
 /* ar.c - Archive modify and extract.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
 /* ar.c - Archive modify and extract.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006
+   2001, 2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
    when name truncated. No way to specify pos_end. Error messages should be
    more consistent.  */
 
    when name truncated. No way to specify pos_end. Error messages should be
    more consistent.  */
 
+#include "sysdep.h"
 #include "bfd.h"
 #include "libiberty.h"
 #include "progress.h"
 #include "bfd.h"
 #include "libiberty.h"
 #include "progress.h"
-#include "bucomm.h"
 #include "aout/ar.h"
 #include "libbfd.h"
 #include "aout/ar.h"
 #include "libbfd.h"
+#include "bucomm.h"
 #include "arsup.h"
 #include "filenames.h"
 #include "binemul.h"
 #include "arsup.h"
 #include "filenames.h"
 #include "binemul.h"
@@ -257,9 +258,9 @@ usage (int help)
   -V --version                 Print version information\n"));
     }
 
   -V --version                 Print version information\n"));
     }
 
-  list_supported_targets (program_name, stderr);
+  list_supported_targets (program_name, s);
 
 
-  if (help)
+  if (REPORT_BUGS_TO[0] && help)
     fprintf (s, _("Report bugs to %s\n"), REPORT_BUGS_TO);
 
   xexit (help ? 0 : 1);
     fprintf (s, _("Report bugs to %s\n"), REPORT_BUGS_TO);
 
   xexit (help ? 0 : 1);
@@ -777,10 +778,10 @@ open_inarch (const char *archive_filename, const char *file)
 static void
 print_contents (bfd *abfd)
 {
 static void
 print_contents (bfd *abfd)
 {
-  int ncopied = 0;
+  size_t ncopied = 0;
   char *cbuf = xmalloc (BUFSIZE);
   struct stat buf;
   char *cbuf = xmalloc (BUFSIZE);
   struct stat buf;
-  long size;
+  size_t size;
   if (bfd_stat_arch_elt (abfd, &buf) != 0)
     /* xgettext:c-format */
     fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
   if (bfd_stat_arch_elt (abfd, &buf) != 0)
     /* xgettext:c-format */
     fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
@@ -795,8 +796,8 @@ print_contents (bfd *abfd)
   while (ncopied < size)
     {
 
   while (ncopied < size)
     {
 
-      int nread;
-      int tocopy = size - ncopied;
+      size_t nread;
+      size_t tocopy = size - ncopied;
       if (tocopy > BUFSIZE)
        tocopy = BUFSIZE;
 
       if (tocopy > BUFSIZE)
        tocopy = BUFSIZE;
 
@@ -805,7 +806,12 @@ print_contents (bfd *abfd)
        /* xgettext:c-format */
        fatal (_("%s is not a valid archive"),
               bfd_get_filename (bfd_my_archive (abfd)));
        /* xgettext:c-format */
        fatal (_("%s is not a valid archive"),
               bfd_get_filename (bfd_my_archive (abfd)));
-      fwrite (cbuf, 1, nread, stdout);
+
+      /* fwrite in mingw32 may return int instead of size_t. Cast the
+        return value to size_t to avoid comparison between signed and
+        unsigned values.  */
+      if ((size_t) fwrite (cbuf, 1, nread, stdout) != nread)
+       fatal ("stdout: %s", strerror (errno));
       ncopied += tocopy;
     }
   free (cbuf);
       ncopied += tocopy;
     }
   free (cbuf);
@@ -826,9 +832,9 @@ extract_file (bfd *abfd)
 {
   FILE *ostream;
   char *cbuf = xmalloc (BUFSIZE);
 {
   FILE *ostream;
   char *cbuf = xmalloc (BUFSIZE);
-  int nread, tocopy;
-  long ncopied = 0;
-  long size;
+  size_t nread, tocopy;
+  size_t ncopied = 0;
+  size_t size;
   struct stat buf;
 
   if (bfd_stat_arch_elt (abfd, &buf) != 0)
   struct stat buf;
 
   if (bfd_stat_arch_elt (abfd, &buf) != 0)
@@ -836,10 +842,6 @@ extract_file (bfd *abfd)
     fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
   size = buf.st_size;
 
     fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
   size = buf.st_size;
 
-  if (size < 0)
-    /* xgettext:c-format */
-    fatal (_("stat returns negative size for %s"), bfd_get_filename (abfd));
-
   if (verbose)
     printf ("x - %s\n", bfd_get_filename (abfd));
 
   if (verbose)
     printf ("x - %s\n", bfd_get_filename (abfd));
 
@@ -888,7 +890,12 @@ extract_file (bfd *abfd)
 
            output_file = ostream;
          }
 
            output_file = ostream;
          }
-       fwrite (cbuf, 1, nread, ostream);
+
+       /* fwrite in mingw32 may return int instead of size_t. Cast
+          the return value to size_t to avoid comparison between
+          signed and unsigned values.  */
+       if ((size_t) fwrite (cbuf, 1, nread, ostream) != nread)
+         fatal ("%s: %s", output_filename, strerror (errno));
        ncopied += tocopy;
       }
 
        ncopied += tocopy;
       }
 
This page took 0.02559 seconds and 4 git commands to generate.