bfd: add breadchr

Reading stops after an EOF or a specified charecter.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Andrew Vagin 2015-10-26 20:20:42 +03:00 committed by Pavel Emelyanov
parent 64b00b3b09
commit 1d8fcb6b94
2 changed files with 7 additions and 1 deletions

7
bfd.c
View file

@ -168,6 +168,11 @@ static char *strnchr(char *str, unsigned int len, char c)
}
char *breadline(struct bfd *f)
{
return breadchr(f, '\n');
}
char *breadchr(struct bfd *f, char c)
{
struct xbuf *b = &f->b;
bool refilled = false;
@ -175,7 +180,7 @@ char *breadline(struct bfd *f)
unsigned int ss = 0;
again:
n = strnchr(b->data + ss, b->sz - ss, '\n');
n = strnchr(b->data + ss, b->sz - ss, c);
if (n) {
char *ret;

View file

@ -31,6 +31,7 @@ int bfdopenr(struct bfd *f);
int bfdopenw(struct bfd *f);
void bclose(struct bfd *f);
char *breadline(struct bfd *f);
char *breadchr(struct bfd *f, char c);
int bwrite(struct bfd *f, const void *buf, int sz);
struct iovec;
int bwritev(struct bfd *f, const struct iovec *iov, int cnt);