may interleave fseek*/ftell* calls with m_getfld() calls. This
eliminates the need for m_getfld() to call fseek() when called
by inc(1) and scan(1).
void m_eomsbr (m_getfld_state_t, int (*)(int));
void m_getfld_state_reset (m_getfld_state_t *);
void m_getfld_state_destroy (m_getfld_state_t *);
void m_eomsbr (m_getfld_state_t, int (*)(int));
void m_getfld_state_reset (m_getfld_state_t *);
void m_getfld_state_destroy (m_getfld_state_t *);
+void m_getfld_track_filepos (m_getfld_state_t *, FILE *);
int m_getfld (m_getfld_state_t *, unsigned char[NAMESZ], unsigned char *, int *, FILE *);
int m_gmprot (void);
char *m_maildir (char *);
int m_getfld (m_getfld_state_t *, unsigned char[NAMESZ], unsigned char *, int *, FILE *);
int m_gmprot (void);
char *m_maildir (char *);
int edelimlen;
int (*eom_action)(int);
int state;
int edelimlen;
int (*eom_action)(int);
int state;
s->fdelimlen = s->edelimlen = 0;
s->eom_action = NULL;
s->state = FLD;
s->fdelimlen = s->edelimlen = 0;
s->eom_action = NULL;
s->state = FLD;
}
/* scan() needs to force a state an initial state of FLD for each message. */
}
/* scan() needs to force a state an initial state of FLD for each message. */
+/* If the caller interleaves ftell*()/fseek*() calls with m_getfld()
+ calls, m_getfld() must keep track of the file position. The caller
+ must use this function to inform m_getfld(). */
+void
+m_getfld_track_filepos (m_getfld_state_t *gstate, FILE *iob) {
+ if (! *gstate) {
+ m_getfld_state_init (gstate, iob);
+ }
+
+ (*gstate)->track_filepos = 1;
+}
+
void m_getfld_state_destroy (m_getfld_state_t *gstate) {
m_getfld_state_t s = *gstate;
void m_getfld_state_destroy (m_getfld_state_t *gstate) {
m_getfld_state_t s = *gstate;
readpos shift code being currently unused. */
s->iob = iob;
readpos shift code being currently unused. */
s->iob = iob;
- if (pos != 0 || s->last_internal_pos != 0) {
+ if (s->track_filepos && (pos != 0 || s->last_internal_pos != 0)) {
if (s->last_internal_pos == 0) {
s->total_bytes_read = pos;
} else {
if (s->last_internal_pos == 0) {
s->total_bytes_read = pos;
} else {
static void
leave_getfld (m_getfld_state_t s) {
static void
leave_getfld (m_getfld_state_t s) {
- /* Save the internal file position that we use for the input buffer. */
- s->last_internal_pos = ftello (s->iob);
-
- /* Set file stream position so that callers can use ftell(). */
s->total_bytes_read += s->bytes_read;
s->total_bytes_read += s->bytes_read;
- fseeko (s->iob, s->total_bytes_read, SEEK_SET);
- s->last_caller_pos = ftello (s->iob);
+
+ if (s->track_filepos) {
+ /* Save the internal file position that we use for the input buffer. */
+ s->last_internal_pos = ftello (s->iob);
+
+ /* Set file stream position so that callers can use ftell(). */
+ fseeko (s->iob, s->total_bytes_read, SEEK_SET);
+ s->last_caller_pos = ftello (s->iob);
+ }
* draft into the linked list of header fields for
* the new MIME message.
*/
* draft into the linked list of header fields for
* the new MIME message.
*/
+ m_getfld_track_filepos (&gstate, in);
for (compnum = 1;;) {
int bufsz = sizeof buf;
switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
for (compnum = 1;;) {
int bufsz = sizeof buf;
switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
* Parse the header fields for this
* content into a linked list.
*/
* Parse the header fields for this
* content into a linked list.
*/
+ m_getfld_track_filepos (&gstate, in);
for (compnum = 1;;) {
int bufsz = sizeof buf;
switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
for (compnum = 1;;) {
int bufsz = sizeof buf;
switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
* Scan through the message and examine the various header fields,
* as well as locate the beginning of the message body.
*/
* Scan through the message and examine the various header fields,
* as well as locate the beginning of the message body.
*/
+ m_getfld_track_filepos (&gstate, in);
for (compnum = 1;;) {
int bufsz = sizeof buffer;
switch (state = m_getfld (&gstate, name, buffer, &bufsz, in)) {
for (compnum = 1;;) {
int bufsz = sizeof buffer;
switch (state = m_getfld (&gstate, name, buffer, &bufsz, in)) {