* doc/Makefile.am (config.texi): Emit a @set UPDATED command to
[deliverable/binutils-gdb.git] / binutils / strings.c
index 67c601f3b91b9ea16f94c937fa0c68e7ac37c915..2fcdb95e2086c107ef78c54bcf0585a46aac2896 100644 (file)
@@ -1,6 +1,6 @@
 /* strings -- print the strings of printable characters in files
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003 Free Software Foundation, Inc.
+   2002, 2003, 2004 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -67,6 +67,7 @@
 #include "bucomm.h"
 #include "libiberty.h"
 #include "safe-ctype.h"
+#include <sys/stat.h>
 
 /* Some platforms need to put stdin into binary mode, to read
     binary files.  */
@@ -104,6 +105,13 @@ typedef off64_t file_off;
 typedef off_t file_off;
 #define file_open(s,m) fopen(s, m)
 #endif
+#ifdef HAVE_STAT64
+typedef struct stat64 statbuf;
+#define file_stat(f,s) stat64(f, s)
+#else
+typedef struct stat statbuf;
+#define file_stat(f,s) stat(f, s)
+#endif
 
 /* Radix for printing addresses (must be 8, 10 or 16).  */
 static int address_radix;
@@ -317,7 +325,7 @@ strings_a_section (bfd *abfd, asection *sect, void *filearg)
 
   if ((sect->flags & DATA_FLAGS) == DATA_FLAGS)
     {
-      bfd_size_type sz = bfd_get_section_size_before_reloc (sect);
+      bfd_size_type sz = bfd_get_section_size (sect);
       void *mem = xmalloc (sz);
 
       if (bfd_get_section_contents (abfd, sect, mem, (file_ptr) 0, sz))
@@ -370,6 +378,18 @@ strings_object_file (const char *file)
 static bfd_boolean
 strings_file (char *file)
 {
+  statbuf st;
+
+  if (file_stat (file, &st) < 0)
+    {
+      if (errno == ENOENT)
+       non_fatal (_("'%s': No such file"), file);
+      else
+       non_fatal (_("Warning: could not locate '%s'.  reason: %s"),
+                  file, strerror (errno));
+      return FALSE;
+    }
+
   /* If we weren't told to scan the whole file,
      try to open it as an object file and only look at
      initialized data sections.  If that fails, fall back to the
@@ -509,7 +529,7 @@ print_strings (const char *filename, FILE *stream, file_off address,
        }
 
       /* We found a run of `string_min' graphic characters.  Print up
-         to the next non-graphic character.  */
+        to the next non-graphic character.  */
 
       if (print_filenames)
        printf ("%s: ", filename);
@@ -554,7 +574,8 @@ print_strings (const char *filename, FILE *stream, file_off address,
 #else
 # if !BFD_HOST_64BIT_LONG
            if (start != (unsigned long) start)
-             printf ("%lx%8.8lx ", start >> 32, start & 0xffffffff);
+             printf ("%lx%8.8lx ", (unsigned long) (start >> 32),
+                     (unsigned long) (start & 0xffffffff));
            else
 # endif
 #endif
@@ -634,7 +655,7 @@ usage (FILE *stream, int status)
   -f --print-file-name      Print the name of the file before each string\n\
   -n --bytes=[number]       Locate & print any NUL-terminated sequence of at\n\
   -<number>                 least [number] characters (default 4).\n\
-  -t --radix={o,x,d}        Print the location of the string in base 8, 10 or 16\n\
+  -t --radix={o,d,x}        Print the location of the string in base 8, 10 or 16\n\
   -o                        An alias for --radix=o\n\
   -T --target=<BFDNAME>     Specify the binary file format\n\
   -e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
This page took 0.023429 seconds and 4 git commands to generate.