summaryrefslogtreecommitdiffstats
path: root/src/src/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/src/strings.c')
-rw-r--r--src/src/strings.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/src/strings.c b/src/src/strings.c
index 442901e5..f60e4b4d 100644
--- a/src/src/strings.c
+++ b/src/src/strings.c
@@ -1,28 +1,20 @@
/* Print the strings of printable characters in files.
- Copyright (C) 2005-2010, 2012 Red Hat, Inc.
- This file is part of Red Hat elfutils.
+ Copyright (C) 2005-2010, 2012, 2014 Red Hat, Inc.
+ This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2005.
- Red Hat elfutils is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by the
- Free Software Foundation; version 2 of the License.
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
- Red Hat elfutils is distributed in the hope that it will be useful, but
+ elfutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with Red Hat elfutils; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
-
- Red Hat elfutils is an included package of the Open Invention Network.
- An included package of the Open Invention Network is a package for which
- Open Invention Network licensees cross-license their patents. No patent
- license is granted, either expressly or impliedly, by designation as an
- included package. Should you wish to participate in the Open Invention
- Network licensing program, please visit www.openinventionnetwork.com
- <http://www.openinventionnetwork.com>. */
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
@@ -124,8 +116,15 @@ static bool char_7bit;
/* True if file names should be printed before strings. */
static bool print_file_name;
-/* Location print format string. */
-static const char *locfmt;
+/* Radix for printed numbers. */
+static enum
+{
+ radix_none = 0,
+ radix_decimal,
+ radix_hex,
+ radix_octal
+} radix = radix_none;
+
/* Page size in use. */
static size_t ps;
@@ -287,16 +286,16 @@ parse_opt (int key, char *arg,
switch (arg[0])
{
case 'd':
- locfmt = "%7" PRId64 " ";
+ radix = radix_decimal;
break;
case 'o':
octfmt:
- locfmt = "%7" PRIo64 " ";
+ radix = radix_octal;
break;
case 'x':
- locfmt = "%7" PRIx64 " ";
+ radix = radix_hex;
break;
default:
@@ -363,8 +362,11 @@ process_chunk_mb (const char *fname, const unsigned char *buf, off64_t to,
fputs_unlocked (": ", stdout);
}
- if (unlikely (locfmt != NULL))
- printf (locfmt, (int64_t) to - len - (buf - start));
+ if (unlikely (radix != radix_none))
+ printf ((radix == radix_octal ? "%7" PRIo64 " "
+ : (radix == radix_decimal ? "%7" PRId64 " "
+ : "%7" PRIx64 " ")),
+ (int64_t) to - len - (buf - start));
if (unlikely (*unprinted != NULL))
{
@@ -428,8 +430,11 @@ process_chunk (const char *fname, const unsigned char *buf, off64_t to,
fputs_unlocked (": ", stdout);
}
- if (likely (locfmt != NULL))
- printf (locfmt, (int64_t) to - len - (buf - start));
+ if (likely (radix != radix_none))
+ printf ((radix == radix_octal ? "%7" PRIo64 " "
+ : (radix == radix_decimal ? "%7" PRId64 " "
+ : "%7" PRIx64 " ")),
+ (int64_t) to - len - (buf - start));
if (unlikely (*unprinted != NULL))
{
@@ -460,13 +465,6 @@ process_chunk (const char *fname, const unsigned char *buf, off64_t to,
static void *
map_file (int fd, off64_t start_off, off64_t fdlen, size_t *map_sizep)
{
-#if _MUDFLAP
- (void) fd;
- (void) start_off;
- (void) fdlen;
- (void) map_sizep;
- return MAP_FAILED;
-#else
/* Maximum size we mmap. We use an #ifdef to avoid overflows on
32-bit machines. 64-bit machines these days do not have usable
address spaces larger than about 43 bits. Not that any file
@@ -508,7 +506,6 @@ map_file (int fd, off64_t start_off, off64_t fdlen, size_t *map_sizep)
*map_sizep = map_size;
return mem;
-#endif
}