Commit 1d8fcb6b authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

bfd: add breadchr

Reading stops after an EOF or a specified charecter.
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 64b00b3b
...@@ -168,6 +168,11 @@ static char *strnchr(char *str, unsigned int len, char c) ...@@ -168,6 +168,11 @@ static char *strnchr(char *str, unsigned int len, char c)
} }
char *breadline(struct bfd *f) char *breadline(struct bfd *f)
{
return breadchr(f, '\n');
}
char *breadchr(struct bfd *f, char c)
{ {
struct xbuf *b = &f->b; struct xbuf *b = &f->b;
bool refilled = false; bool refilled = false;
...@@ -175,7 +180,7 @@ char *breadline(struct bfd *f) ...@@ -175,7 +180,7 @@ char *breadline(struct bfd *f)
unsigned int ss = 0; unsigned int ss = 0;
again: again:
n = strnchr(b->data + ss, b->sz - ss, '\n'); n = strnchr(b->data + ss, b->sz - ss, c);
if (n) { if (n) {
char *ret; char *ret;
......
...@@ -31,6 +31,7 @@ int bfdopenr(struct bfd *f); ...@@ -31,6 +31,7 @@ int bfdopenr(struct bfd *f);
int bfdopenw(struct bfd *f); int bfdopenw(struct bfd *f);
void bclose(struct bfd *f); void bclose(struct bfd *f);
char *breadline(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); int bwrite(struct bfd *f, const void *buf, int sz);
struct iovec; struct iovec;
int bwritev(struct bfd *f, const struct iovec *iov, int cnt); int bwritev(struct bfd *f, const struct iovec *iov, int cnt);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment