* strings.c (get_char): Dispense with buf[]. Instead shift

chars into big-endian value and byte-swap later if
	little-endian.  Don't EOF check value read from object.
This commit is contained in:
Alan Modra 2013-03-06 13:40:51 +00:00
parent 6c77229c00
commit c54e2ec142
2 changed files with 12 additions and 19 deletions

View file

@ -1,3 +1,9 @@
2013-03-07 Alan Modra <amodra@gmail.com>
* strings.c (get_char): Dispense with buf[]. Instead shift
chars into big-endian value and byte-swap later if
little-endian. Don't EOF check value read from object.
2013-03-05 Corinna Vinschen <vinschen@redhat.com> 2013-03-05 Corinna Vinschen <vinschen@redhat.com>
* configure.in: Build DLL tools on x86_64-*-cygwin* as well. * configure.in: Build DLL tools on x86_64-*-cygwin* as well.

View file

@ -455,8 +455,7 @@ static long
get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic) get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
{ {
int c, i; int c, i;
long r = EOF; long r = 0;
unsigned char buf[4];
for (i = 0; i < encoding_bytes; i++) for (i = 0; i < encoding_bytes; i++)
{ {
@ -484,34 +483,22 @@ get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
} }
(*address)++; (*address)++;
buf[i] = c; r = (r << 8) | (c & 0xff);
} }
switch (encoding) switch (encoding)
{ {
case 'S': default:
case 's':
r = buf[0];
break;
case 'b':
r = (buf[0] << 8) | buf[1];
break; break;
case 'l': case 'l':
r = buf[0] | (buf[1] << 8); r = ((r & 0xff) << 8) | ((r & 0xff00) >> 8);
break;
case 'B':
r = ((long) buf[0] << 24) | ((long) buf[1] << 16) |
((long) buf[2] << 8) | buf[3];
break; break;
case 'L': case 'L':
r = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) | r = (((r & 0xff) << 24) | ((r & 0xff00) << 8)
((long) buf[3] << 24); | ((r & 0xff0000) >> 8) | ((r & 0xff000000) >> 24));
break; break;
} }
if (r == EOF)
return 0;
return r; return r;
} }