struct rfc2045 *rfc2045_fromfd(int fd) { struct rfc2045 *rfc; char buf[BUFSIZ]; int n; off_t orig_pos; if ((orig_pos=lseek(fd, 0L, SEEK_CUR)) == (off_t)-1) return (NULL); if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) return (NULL); if ((rfc=rfc2045_alloc()) == 0) return (NULL); while ((n=read(fd, buf, sizeof(buf))) > 0) rfc2045_parse(rfc, buf, n); rfc2045_parse_partial(rfc); if (lseek(fd, orig_pos, SEEK_SET) == (off_t)-1) { rfc2045_free(rfc); rfc=0; } return (rfc); }
void rfc2045_parse(struct rfc2045 *h, const char *buf, size_t s) { size_t l; while (s) { for (l=0; l<s; l++) if (buf[l] == '\n') break; if (l < s && buf[l] == '\n') { ++l; rfc2045_add_workbuf(h, buf, l); doline(h); h->workbuflen=0; } else rfc2045_add_workbuf(h, buf, l); buf += l; s -= l; } if (h->workbuflen > 1024) rfc2045_parse_partial(h); }