+ return TRUE;
+}
+\f
+/* Read the next character, return EOF if none available.
+ Assume that STREAM is positioned so that the next byte read
+ is at address ADDRESS in the file.
+
+ If STREAM is NULL, do not read from it.
+ The caller can supply a buffer of characters
+ to be processed before the data in STREAM.
+ MAGIC is the address of the buffer and
+ MAGICCOUNT is how many characters are in it. */
+
+static long
+get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
+{
+ int c, i;
+ long r = 0;
+
+ for (i = 0; i < encoding_bytes; i++)
+ {
+ if (*magiccount)
+ {
+ (*magiccount)--;
+ c = *(*magic)++;
+ }
+ else
+ {
+ if (stream == NULL)
+ return EOF;
+
+ /* Only use getc_unlocked if we found a declaration for it.
+ Otherwise, libc is not thread safe by default, and we
+ should not use it. */
+
+#if defined(HAVE_GETC_UNLOCKED) && HAVE_DECL_GETC_UNLOCKED
+ c = getc_unlocked (stream);
+#else
+ c = getc (stream);
+#endif
+ if (c == EOF)
+ return EOF;
+ }
+
+ (*address)++;
+ r = (r << 8) | (c & 0xff);
+ }
+
+ switch (encoding)
+ {
+ default:
+ break;
+ case 'l':
+ r = ((r & 0xff) << 8) | ((r & 0xff00) >> 8);
+ break;
+ case 'L':
+ r = (((r & 0xff) << 24) | ((r & 0xff00) << 8)
+ | ((r & 0xff0000) >> 8) | ((r & 0xff000000) >> 24));
+ break;
+ }
+
+ return r;
+}
+
+/* Throw away one byte of a (possibly) multi-byte char C, updating
+ address and buffer to suit. */
+
+static void
+unget_part_char (long c, file_ptr *address, int *magiccount, char **magic)
+{
+ static char tmp[4];
+
+ if (encoding_bytes > 1)
+ {
+ *address -= encoding_bytes - 1;
+
+ if (*magiccount == 0)
+ {
+ /* If no magic buffer exists, use temp buffer. */
+ switch (encoding)
+ {
+ default:
+ break;
+ case 'b':
+ tmp[0] = c & 0xff;
+ *magiccount = 1;
+ break;
+ case 'l':
+ tmp[0] = (c >> 8) & 0xff;
+ *magiccount = 1;
+ break;
+ case 'B':
+ tmp[0] = (c >> 16) & 0xff;
+ tmp[1] = (c >> 8) & 0xff;
+ tmp[2] = c & 0xff;
+ *magiccount = 3;
+ break;
+ case 'L':
+ tmp[0] = (c >> 8) & 0xff;
+ tmp[1] = (c >> 16) & 0xff;
+ tmp[2] = (c >> 24) & 0xff;
+ *magiccount = 3;
+ break;
+ }
+ *magic = tmp;
+ }
+ else
+ {
+ /* If magic buffer exists, rewind. */
+ *magic -= encoding_bytes - 1;
+ *magiccount += encoding_bytes - 1;
+ }
+ }