summaryrefslogtreecommitdiff
path: root/binutils/strings.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2008-02-15 10:20:09 +0000
committerNick Clifton <nickc@redhat.com>2008-02-15 10:20:09 +0000
commit4871741349fd79756ba7f8c37e2a92fd18cfdb08 (patch)
treedc03432914a5de71abc5e4e3f3ef236c74f94699 /binutils/strings.c
parent1a592a12a78bbf082399b8f393c82a531467c9b1 (diff)
downloadbinutils-redhat-4871741349fd79756ba7f8c37e2a92fd18cfdb08.tar.gz
PR binutils/5713
* strings.c (integer_arg): Delete function. (string_min): Initialise to 4. (main): Use strtoul to parse integer arguments. Move check for an invalid string length to after all the arguments have been parsed. (usage): Use indentation to indicate that -<n> is a another form of the --bytes= command line option.
Diffstat (limited to 'binutils/strings.c')
-rw-r--r--binutils/strings.c63
1 files changed, 6 insertions, 57 deletions
diff --git a/binutils/strings.c b/binutils/strings.c
index cf4b336f5c..40b53b8fed 100644
--- a/binutils/strings.c
+++ b/binutils/strings.c
@@ -160,7 +160,6 @@ typedef struct
static void strings_a_section (bfd *, asection *, void *);
static bfd_boolean strings_object_file (const char *);
static bfd_boolean strings_file (char *file);
-static int integer_arg (char *s);
static void print_strings (const char *, FILE *, file_off, int, int, char *);
static void usage (FILE *, int);
static long get_char (FILE *, file_off *, int *, char **);
@@ -185,7 +184,7 @@ main (int argc, char **argv)
expandargv (&argc, &argv);
- string_min = -1;
+ string_min = 4;
print_addresses = FALSE;
print_filenames = FALSE;
datasection_only = TRUE;
@@ -210,9 +209,7 @@ main (int argc, char **argv)
usage (stdout, 0);
case 'n':
- string_min = integer_arg (optarg);
- if (string_min < 1)
- fatal (_("invalid number %s"), optarg);
+ string_min = (int) strtoul (optarg, NULL, 0);
break;
case 'o':
@@ -262,16 +259,13 @@ main (int argc, char **argv)
usage (stderr, 1);
default:
- if (string_min < 0)
- string_min = optc - '0';
- else
- string_min = string_min * 10 + optc - '0';
+ string_min = (int) strtoul (argv[optind - 1] + 1, NULL, 0);
break;
}
}
- if (string_min <= 0)
- string_min = 4;
+ if (string_min < 1)
+ fatal (_("invalid minimum string length %d"), string_min);
switch (encoding)
{
@@ -666,51 +660,6 @@ print_strings (const char *filename, FILE *stream, file_off address,
}
}
-/* Parse string S as an integer, using decimal radix by default,
- but allowing octal and hex numbers as in C. */
-
-static int
-integer_arg (char *s)
-{
- int value;
- int radix = 10;
- char *p = s;
- int c;
-
- if (*p != '0')
- radix = 10;
- else if (*++p == 'x')
- {
- radix = 16;
- p++;
- }
- else
- radix = 8;
-
- value = 0;
- while (((c = *p++) >= '0' && c <= '9')
- || (radix == 16 && (c & ~40) >= 'A' && (c & ~40) <= 'Z'))
- {
- value *= radix;
- if (c >= '0' && c <= '9')
- value += c - '0';
- else
- value += (c & ~40) - 'A';
- }
-
- if (c == 'b')
- value *= 512;
- else if (c == 'B')
- value *= 1024;
- else
- p--;
-
- if (*p)
- fatal (_("invalid integer argument %s"), s);
-
- return value;
-}
-
static void
usage (FILE *stream, int status)
{
@@ -720,7 +669,7 @@ usage (FILE *stream, int status)
-a - --all Scan the entire file, not just the data section\n\
-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\
+ -<number> least [number] characters (default 4).\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\