char *np, *vp;
CT ct;
HF hp;
- long filepos;
+ m_getfld_state_t gstate = 0;
/* allocate the content structure */
if (!(ct = (CT) calloc (1, sizeof(*ct))))
ct->c_fp = in;
ct->c_file = add (file, NULL);
- ct->c_begin = (filepos = ftell (ct->c_fp)) + 1;
+ ct->c_begin = ftell (ct->c_fp) + 1;
/*
* Parse the header fields for this
* content into a linked list.
*/
- for (compnum = 1, state = FLD;;) {
+ for (compnum = 1;;) {
int bufsz = sizeof buf;
- switch (state = m_getfld (state, name, buf, &bufsz, in)) {
+ switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) {
case FLD:
case FLDPLUS:
- case FLDEOF:
compnum++;
- filepos += bufsz;
/* get copies of the buffers */
np = add (name, NULL);
/* if necessary, get rest of field */
while (state == FLDPLUS) {
bufsz = sizeof buf;
- state = m_getfld (state, name, buf, &bufsz, in);
+ state = m_getfld (&gstate, name, buf, &bufsz, in);
vp = add (buf, vp); /* add to previous value */
}
/* Now add the header data to the list */
add_header (ct, np, vp);
- /* continue, if this isn't the last header field */
- if (state != FLDEOF) {
- ct->c_begin = filepos + 1;
- continue;
- }
- /* else fall... */
+ /* continue, to see if this isn't the last header field */
+ ct->c_begin = ftell (in) + 1;
+ continue;
case BODY:
- case BODYEOF:
- filepos += bufsz;
- ct->c_begin = filepos - strlen (buf);
+ ct->c_begin = ftell (in) - strlen (buf);
break;
case FILEEOF:
- filepos += bufsz;
- ct->c_begin = filepos;
+ ct->c_begin = ftell (in);
break;
case LENERR:
/* break out of the loop */
break;
}
+ m_getfld_state_destroy (&gstate);
/*
* Read the content headers. We will parse the