* windres.c (define_resource): Use zero for timestamp, making
[deliverable/binutils-gdb.git] / binutils / strings.c
index 00cfb6dc66963c76d67b98bd9464b861ca0162b1..d5916305f8a1f3ae20e144b1ab22cb1cc9a212f1 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, 2004, 2005, 2006, 2007, 2008, 2009
+   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -65,7 +65,6 @@
 #include "getopt.h"
 #include "libiberty.h"
 #include "safe-ctype.h"
-#include <sys/stat.h>
 #include "bucomm.h"
 
 #define STRING_ISGRAPHIC(c) \
@@ -456,8 +455,7 @@ static long
 get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
 {
   int c, i;
-  long r = EOF;
-  unsigned char buf[4];
+  long r = 0;
 
   for (i = 0; i < encoding_bytes; i++)
     {
@@ -485,34 +483,22 @@ get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
        }
 
       (*address)++;
-      buf[i] = c;
+      r = (r << 8) | (c & 0xff);
     }
 
   switch (encoding)
     {
-    case 'S':
-    case 's':
-      r = buf[0];
-      break;
-    case 'b':
-      r = (buf[0] << 8) | buf[1];
+    default:
       break;
     case 'l':
-      r = buf[0] | (buf[1] << 8);
-      break;
-    case 'B':
-      r = ((long) buf[0] << 24) | ((long) buf[1] << 16) |
-       ((long) buf[2] << 8) | buf[3];
+      r = ((r & 0xff) << 8) | ((r & 0xff00) >> 8);
       break;
     case 'L':
-      r = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) |
-       ((long) buf[3] << 24);
+      r = (((r & 0xff) << 24) | ((r & 0xff00) << 8)
+          | ((r & 0xff0000) >> 8) | ((r & 0xff000000) >> 24));
       break;
     }
 
-  if (r == EOF)
-    return 0;
-
   return r;
 }
 \f
@@ -549,7 +535,10 @@ print_strings (const char *filename, FILE *stream, file_ptr address,
        {
          c = get_char (stream, &address, &magiccount, &magic);
          if (c == EOF)
-           return;
+           {
+             free (buf);
+             return;
+           }
          if (! STRING_ISGRAPHIC (c))
            /* Found a non-graphic.  Try again starting with next char.  */
            goto tryline;
@@ -638,6 +627,7 @@ print_strings (const char *filename, FILE *stream, file_ptr address,
 
       putchar ('\n');
     }
+  free (buf);
 }
 \f
 static void
This page took 0.024163 seconds and 4 git commands to generate.