X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/942561da2455ee50a1eb82c8c4f2bdb5e25133d1..36e3d7dc4bc9905a9b9074defd26ee6c32e1a6b9:/sbr/m_getfld.c diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 9315059d..531381d8 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -347,7 +347,7 @@ void m_getfld_state_destroy (m_getfld_state_t *gstate) { static void enter_getfld (m_getfld_state_t *gstate, FILE *iob) { m_getfld_state_t s; - off_t pos = ftello (iob); + off_t pos; if (! *gstate) { m_getfld_state_init (gstate, iob); @@ -363,7 +363,11 @@ enter_getfld (m_getfld_state_t *gstate, FILE *iob) { readpos shift code being currently unused. */ s->iob = iob; - if (s->track_filepos && (pos != 0 || s->last_internal_pos != 0)) { + if (!s->track_filepos) + return; + + pos = ftello(iob); + if (pos != 0 || s->last_internal_pos != 0) { if (s->last_internal_pos == 0) { s->total_bytes_read = pos; } else { @@ -444,29 +448,21 @@ read_more (m_getfld_state_t s) { but EOF is typically 0xffffffff. */ static int Getc (m_getfld_state_t s) { - if (s->end - s->readpos < 1) { - if (read_more (s) == 0) { - /* Pretend that we read a character. That's what stdio does. */ - ++s->readpos; - return EOF; - } + if (s->end - s->readpos < 1 && read_more (s) == 0) { + return EOF; + } else { + ++s->bytes_read; + return s->readpos < s->end ? (unsigned char) *s->readpos++ : EOF; } - - ++s->bytes_read; - return s->readpos < s->end ? (unsigned char) *s->readpos++ : EOF; } static int Peek (m_getfld_state_t s) { - if (s->end - s->readpos < 1) { - if (read_more (s) == 0) { - /* Pretend that we read a character. That's what stdio does. */ - ++s->readpos; - return EOF; - } + if (s->end - s->readpos < 1 && read_more (s) == 0) { + return EOF; + } else { + return s->readpos < s->end ? (unsigned char) *s->readpos : EOF; } - - return s->readpos < s->end ? (unsigned char) *s->readpos : EOF; } static int