char * iobuf_getline(struct iobuf *iobuf, size_t *rlen) { char *buf; size_t len, i; buf = iobuf_data(iobuf); len = iobuf_len(iobuf); for (i = 0; i + 1 <= len; i++) if (buf[i] == '\n') { /* Note: the returned address points into the iobuf * buffer. We NUL-end it for convenience, and discard * the data from the iobuf, so that the caller doesn't * have to do it. The data remains "valid" as long * as the iobuf does not overwrite it, that is until * the next call to iobuf_normalize() or iobuf_extend(). */ iobuf_drop(iobuf, i + 1); len = (i && buf[i - 1] == '\r') ? i - 1 : i; buf[len] = '\0'; if (rlen) *rlen = len; return (buf); } return (NULL); }
void io_drop(struct io *io, size_t sz) { return iobuf_drop(&io->iobuf, sz); }