commit b19b8dbca985e2f567bb3f476b116ea18c1ca9a2 from: Omar Polo date: Sun Feb 18 22:59:16 2024 UTC bufio: add bufio_drain() commit - 0e0994b2df05d5286a0b1d7fec24819ce2845588 commit + b19b8dbca985e2f567bb3f476b116ea18c1ca9a2 blob - 4122b01441fd4b887a274040156e14a1cda1aa3f blob + c9ff26b0bea6eff0223c407fe289e9344d2f8695 --- bufio.c +++ bufio.c @@ -276,6 +276,18 @@ bufio_read(struct bufio *bio) return (-1); rbuf->len += r; return (r); +} + +size_t +bufio_drain(struct bufio *bio, void *d, size_t len) +{ + struct buf *rbuf = &bio->rbuf; + + if (len > rbuf->len) + len = rbuf->len; + memcpy(d, rbuf->buf, len); + buf_drain(rbuf, len); + return (len); } ssize_t blob - 1737c9fd2ca66ff5e99368d0fcb3a5c2d3f95e64 blob + b079dbe02b0175351fe48d69b61a19779edf4433 --- bufio.h +++ bufio.h @@ -57,6 +57,7 @@ int bufio_starttls(struct bufio *, const char *, int, int bufio_ev(struct bufio *); int bufio_handshake(struct bufio *); ssize_t bufio_read(struct bufio *); +size_t bufio_drain(struct bufio *, void *, size_t); ssize_t bufio_write(struct bufio *); int bufio_compose(struct bufio *, const void *, size_t); int bufio_compose_str(struct bufio *, const char *);