PR 10288
[deliverable/binutils-gdb.git] / binutils / strings.c
index 973045e17c96f11ad8dbdc7ec84556d9459daa5d..06fd8e995b72d1f772129b9d3ec8f2d1d79ab70f 100644 (file)
@@ -1,6 +1,7 @@
 /* strings -- print the strings of printable characters in files
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   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
@@ -53,6 +54,7 @@
    -h          Print the usage message on the standard output.
 
    --version
+   -V
    -v          Print the program version number.
 
    Written by Richard Stallman <rms@gnu.ai.mit.edu>
 #include <sys/stat.h>
 #include "bucomm.h"
 
-/* Some platforms need to put stdin into binary mode, to read
-    binary files.  */
-#ifdef HAVE_SETMODE
-#ifdef _O_BINARY
-#define setmode _setmode
-#endif
-#if O_BINARY
-#include <io.h>
-#define SET_BINARY(f) do { if (!isatty (f)) setmode (f, O_BINARY); } while (0)
-#endif
-#endif
-
 #define STRING_ISGRAPHIC(c) \
       (   (c) >= 0 \
        && (c) <= 255 \
@@ -167,6 +157,8 @@ main (int argc, char **argv)
   int optc;
   int exit_status = 0;
   bfd_boolean files_given = FALSE;
+  char *s;
+  int numeric_opt = 0;
 
 #if defined (HAVE_SETLOCALE)
   setlocale (LC_ALL, "");
@@ -204,7 +196,9 @@ main (int argc, char **argv)
          usage (stdout, 0);
 
        case 'n':
-         string_min = (int) strtoul (optarg, NULL, 0);
+         string_min = (int) strtoul (optarg, &s, 0);
+         if (s != NULL && *s != 0)
+           fatal (_("invalid integer argument %s"), optarg);
          break;
 
        case 'o':
@@ -254,11 +248,17 @@ main (int argc, char **argv)
          usage (stderr, 1);
 
        default:
-         string_min = (int) strtoul (argv[optind - 1] + 1, NULL, 0);
+         numeric_opt = optind;
          break;
        }
     }
 
+  if (numeric_opt != 0)
+    {
+      string_min = (int) strtoul (argv[numeric_opt - 1] + 1, &s, 0);
+      if (s != NULL && *s != 0)
+       fatal (_("invalid integer argument %s"), argv[numeric_opt - 1] + 1);
+    }
   if (string_min < 1)
     fatal (_("invalid minimum string length %d"), string_min);
 
@@ -286,9 +286,7 @@ main (int argc, char **argv)
   if (optind >= argc)
     {
       datasection_only = FALSE;
-#ifdef SET_BINARY
       SET_BINARY (fileno (stdin));
-#endif
       print_strings ("{standard input}", stdin, 0, 0, 0, (char *) NULL);
       files_given = TRUE;
     }
@@ -672,7 +670,7 @@ usage (FILE *stream, int status)
                             s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
   @<file>                   Read options from <file>\n\
   -h --help                 Display this information\n\
-  -v --version              Print the program's version number\n"));
+  -v -V --version           Print the program's version number\n"));
   list_supported_targets (program_name, stream);
   if (REPORT_BUGS_TO[0] && status == 0)
     fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
This page took 0.03515 seconds and 4 git commands to generate.