[CRIU] [PATCH 1/2] bfd: add breadchr
Andrey Vagin
avagin at openvz.org
Mon Oct 26 10:20:42 PDT 2015
From: Andrew Vagin <avagin at openvz.org>
Reading stops after an EOF or a specified charecter.
Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
bfd.c | 7 ++++++-
include/bfd.h | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/bfd.c b/bfd.c
index 81ac2b0..66c318c 100644
--- a/bfd.c
+++ b/bfd.c
@@ -169,13 +169,18 @@ 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;
char *n;
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;
diff --git a/include/bfd.h b/include/bfd.h
index 1dd1ea2..e9b4d53 100644
--- a/include/bfd.h
+++ b/include/bfd.h
@@ -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);
--
2.4.3
More information about the CRIU
mailing list