of bytes read by m_getfld().
{
register unsigned char *bp, *cp, *ep, *sp;
register int cnt, c, i, j, k;
{
register unsigned char *bp, *cp, *ep, *sp;
register int cnt, c, i, j, k;
setup_buffer (iob, &m);
if ((c = Getc(iob)) < 0) {
setup_buffer (iob, &m);
if ((c = Getc(iob)) < 0) {
- *bufsz = 0;
- *buf = 0;
return FILEEOF;
}
if (eom (c, iob)) {
return FILEEOF;
}
if (eom (c, iob)) {
if (c >= 0)
Ungetc(c, iob);
}
if (c >= 0)
Ungetc(c, iob);
}
- *bufsz = 0;
- *buf = 0;
case FLD:
if (c == '\n' || c == '-') {
/* we hit the header/body separator */
case FLD:
if (c == '\n' || c == '-') {
/* we hit the header/body separator */
- while (c != '\n' && (c = Getc(iob)) >= 0)
- ;
+ while (c != '\n' && (c = Getc(iob)) >= 0) {
+ ++bytes_read;
+ }
if (c < 0 || (c = Getc(iob)) < 0 || eom (c, iob)) {
if (! eom_action) {
if (c < 0 || (c = Getc(iob)) < 0 || eom (c, iob)) {
if (! eom_action) {
if (c >= 0)
Ungetc(c, iob);
}
if (c >= 0)
Ungetc(c, iob);
}
- *bufsz = 0;
- *buf = 0;
return FILEEOF;
}
state = BODY;
return FILEEOF;
}
state = BODY;
/* Store current position, ungetting the last character. */
bp = sp = (unsigned char *) m.readpos - 1;
j = (cnt = m.end - m.readpos + 1) < i ? cnt : i;
/* Store current position, ungetting the last character. */
bp = sp = (unsigned char *) m.readpos - 1;
j = (cnt = m.end - m.readpos + 1) < i ? cnt : i;
- while (--j >= 0 && (c = *bp++) != ':' && c != '\n')
+ while (--j >= 0 && (c = *bp++) != ':' && c != '\n') {
j = bp - sp;
if ((cnt -= j) <= 0) {
/* Next to force refill of the buffer here. */
m.readpos = m.end;
if (Getc (iob) == EOF) {
j = bp - sp;
if ((cnt -= j) <= 0) {
/* Next to force refill of the buffer here. */
m.readpos = m.end;
if (Getc (iob) == EOF) {
+ *bufsz = *cp = *buf = 0;
advise (NULL, "eof encountered in field \"%s\"", name);
return FMTERR;
}
advise (NULL, "eof encountered in field \"%s\"", name);
return FMTERR;
}
/* + 1 for the newline */
if (*bufsz < j + 1) {
/* No, it can't. Oh well, guess we'll blow up. */
/* + 1 for the newline */
if (*bufsz < j + 1) {
/* No, it can't. Oh well, guess we'll blow up. */
+ *bufsz = *cp = *buf = 0;
advise (NULL, "eol encountered in field \"%s\"", name);
state = FMTERR;
goto finish;
advise (NULL, "eol encountered in field \"%s\"", name);
state = FMTERR;
goto finish;
* blank line in this case. Simpler parsers (e.g. mhl)
* get extra newlines, but that should be harmless enough,
* right? This is a corrupt message anyway. */
* blank line in this case. Simpler parsers (e.g. mhl)
* get extra newlines, but that should be harmless enough,
* right? This is a corrupt message anyway. */
- /* emulates: fseek (iob, ftell (iob) -(-2 + cnt + 1),
- SEEK_SET) */
+ /* emulates: fseek (iob, ftell (iob) -2), SEEK_SET) */
- /* Reset file stream position so caller, e.g.,
- get_content, can use ftell(), etc. */
- fseek (iob, -cnt - 1, SEEK_CUR);
return BODY;
}
if ((i -= j) <= 0) {
return BODY;
}
if ((i -= j) <= 0) {
+ *bufsz = *cp = *buf = 0;
advise (NULL, "field name \"%s\" exceeds %d bytes", name, NAMESZ - 2);
state = LENERR;
goto finish;
}
}
advise (NULL, "field name \"%s\" exceeds %d bytes", name, NAMESZ - 2);
state = LENERR;
goto finish;
}
}
- while (isspace (*--cp) && cp >= name)
- ;
+ while (isspace (*--cp) && cp >= name) {
+ --bytes_read;
+ }
*++cp = 0;
/* fall through */
*++cp = 0;
/* fall through */
/* Advance the current position to reflect the copy out. */
m.readpos += c;
if (*bufsz < 0) {
/* Advance the current position to reflect the copy out. */
m.readpos += c;
if (*bufsz < 0) {
+ *bufsz = c + bytes_read + 1;
return (state);
}
cp = buf + c;
return (state);
}
cp = buf + c;
+ *bufsz = cp - buf + bytes_read + 1;
char *np, *vp;
CT ct;
HF hp;
char *np, *vp;
CT ct;
HF hp;
/* allocate the content structure */
if (!(ct = (CT) calloc (1, sizeof(*ct))))
/* allocate the content structure */
if (!(ct = (CT) calloc (1, sizeof(*ct))))
ct->c_fp = in;
ct->c_file = add (file, NULL);
ct->c_fp = in;
ct->c_file = add (file, NULL);
- ct->c_begin = ftell (ct->c_fp) + 1;
+ ct->c_begin = (filepos = ftell (ct->c_fp)) + 1;
/*
* Parse the header fields for this
/*
* Parse the header fields for this
case FLDPLUS:
case FLDEOF:
compnum++;
case FLDPLUS:
case FLDEOF:
compnum++;
/* get copies of the buffers */
np = add (name, NULL);
/* get copies of the buffers */
np = add (name, NULL);
/* continue, if this isn't the last header field */
if (state != FLDEOF) {
/* continue, if this isn't the last header field */
if (state != FLDEOF) {
- ct->c_begin = ftell (in) + 1;
+ ct->c_begin = filepos + 1;
continue;
}
/* else fall... */
case BODY:
case BODYEOF:
continue;
}
/* else fall... */
case BODY:
case BODYEOF:
- ct->c_begin = ftell (in) - strlen (buf);
+ filepos += bufsz;
+ ct->c_begin = filepos - strlen (buf);
- ct->c_begin = ftell (in);
+ filepos += bufsz;
+ ct->c_begin = filepos;