[CRIU] [PATCH 12/15] bfd: Rename fields

Pavel Emelyanov xemul at parallels.com
Mon Sep 29 01:49:55 PDT 2014


For reads and writes the names pos and bleft will
have strange meaning, so rename them into smth more
appropriate.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 bfd.c         | 36 ++++++++++++++++++------------------
 include/bfd.h |  4 ++--
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/bfd.c b/bfd.c
index e80120e..1494aa9 100644
--- a/bfd.c
+++ b/bfd.c
@@ -53,8 +53,8 @@ static int buf_get(struct xbuf *xb)
 	list_del_init(&b->l);
 
 	xb->mem = b->mem;
-	xb->pos = xb->mem;
-	xb->bleft = 0;
+	xb->data = xb->mem;
+	xb->sz = 0;
 	xb->buf = b;
 	pr_debug("BUF<\n");
 	return 0;
@@ -70,7 +70,7 @@ static void buf_put(struct xbuf *xb)
 	list_add(&xb->buf->l, &bufs);
 	xb->buf = NULL;
 	xb->mem = NULL;
-	xb->pos = NULL;
+	xb->data = NULL;
 }
 
 int bfdopen(struct bfd *f)
@@ -94,10 +94,10 @@ static int brefill(struct bfd *f)
 	int ret;
 	struct xbuf *b = &f->b;
 
-	memmove(b->mem, b->pos, b->bleft);
-	b->pos = b->mem;
+	memmove(b->mem, b->data, b->sz);
+	b->data = b->mem;
 
-	ret = read(f->fd, b->mem + b->bleft, BUFSIZE - b->bleft);
+	ret = read(f->fd, b->mem + b->sz, BUFSIZE - b->sz);
 	if (ret < 0) {
 		pr_perror("bfd: Error reading file");
 		return -1;
@@ -106,7 +106,7 @@ static int brefill(struct bfd *f)
 	if (ret == 0)
 		return 0;
 
-	b->bleft += ret;
+	b->sz += ret;
 	return 0;
 }
 
@@ -128,19 +128,19 @@ char *breadline(struct bfd *f)
 	unsigned int ss = 0;
 
 again:
-	n = strnchr(b->pos + ss, b->bleft - ss, '\n');
+	n = strnchr(b->data + ss, b->sz - ss, '\n');
 	if (n) {
 		char *ret;
 
-		ret = b->pos;
-		b->pos = n + 1; /* skip the \n found */
+		ret = b->data;
+		b->data = n + 1; /* skip the \n found */
 		*n = '\0';
-		b->bleft -= (b->pos - ret);
+		b->sz -= (b->data - ret);
 		return ret;
 	}
 
 	if (refilled) {
-		if (!b->bleft)
+		if (!b->sz)
 			return NULL;
 
 		/*
@@ -148,24 +148,24 @@ again:
 		 * end, need to report this as full
 		 * line anyway
 		 */
-		b->pos[b->bleft] = '\0';
+		b->data[b->sz] = '\0';
 
 		/*
-		 * The b->pos still points to old data,
+		 * The b->data still points to old data,
 		 * but we say that no bytes left there
 		 * so next call to breadline will not
 		 * "find" these bytes again.
 		 */
-		b->bleft = 0;
-		return b->pos;
+		b->sz = 0;
+		return b->data;
 	}
 
 	/*
-	 * small optimization -- we've scanned b->bleft
+	 * small optimization -- we've scanned b->sz
 	 * symols already, no need to re-scan them after
 	 * the buffer refill.
 	 */
-	ss = b->bleft;
+	ss = b->sz;
 
 	/* no full line in the buffer -- refill one */
 	if (brefill(f))
diff --git a/include/bfd.h b/include/bfd.h
index dbaea16..11dc484 100644
--- a/include/bfd.h
+++ b/include/bfd.h
@@ -3,8 +3,8 @@
 struct bfd_buf;
 struct xbuf {
 	char *mem;		/* buffer */
-	char *pos;		/* position we see bytes at */
-	unsigned int bleft;	/* bytes left after b->pos */
+	char *data;		/* position we see bytes at */
+	unsigned int sz;	/* bytes sitting after b->pos */
 	struct bfd_buf *buf;
 };
 
-- 
1.8.4.2




More information about the CRIU mailing list