-#ifdef _FSTDIO
-# define _ptr _p /* Gag */
-# define _cnt _r /* Retch */
-# define _filbuf __srget /* Puke */
-# define DEFINED__FILBUF_TO_SOMETHING_SPECIFIC
-#endif
+/*
+** This replaces the old approach, which included direct access to
+** stdio internals. It uses one fread() to load a buffer that we
+** manage.
+*/
+#define MSG_INPUT_SIZE 8192
+static struct m_getfld_buffer {
+ unsigned char msg_buf[2 * MSG_INPUT_SIZE];
+ unsigned char *readpos;
+ unsigned char *end; /* One past the last character read in. */
+} m;
+
+static void
+setup_buffer(FILE *iob, struct m_getfld_buffer *m)
+{
+ /*
+ ** Rely on Restrictions that m_getfld() calls on different file
+ ** streams are not interleaved, and no other file stream read
+ ** methods are used. And, the first call to m_getfld (), etc., on
+ ** a stream always reads at least 1 byte.
+ ** I don't think it's necessary to use ftello() because we just
+ ** need to determine whether the current offset is 0 or not.
+ */
+ if (ftell(iob) == 0) {
+ /* A new file stream, so reset the buffer state. */
+ m->readpos = m->end = m->msg_buf;
+ }
+}