Commit 67bbc7ea authored by Pavel Emelyanov's avatar Pavel Emelyanov

bfd: Rename fields

For reads and writes the names pos and bleft will
have strange meaning, so rename them into smth more
appropriate.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 166c58d5
...@@ -63,8 +63,8 @@ static int buf_get(struct xbuf *xb) ...@@ -63,8 +63,8 @@ static int buf_get(struct xbuf *xb)
list_del_init(&b->l); list_del_init(&b->l);
xb->mem = b->mem; xb->mem = b->mem;
xb->pos = xb->mem; xb->data = xb->mem;
xb->bleft = 0; xb->sz = 0;
xb->buf = b; xb->buf = b;
pr_debug("BUF %p <\n", xb->mem); pr_debug("BUF %p <\n", xb->mem);
return 0; return 0;
...@@ -80,7 +80,7 @@ static void buf_put(struct xbuf *xb) ...@@ -80,7 +80,7 @@ static void buf_put(struct xbuf *xb)
list_add(&xb->buf->l, &bufs); list_add(&xb->buf->l, &bufs);
xb->buf = NULL; xb->buf = NULL;
xb->mem = NULL; xb->mem = NULL;
xb->pos = NULL; xb->data = NULL;
} }
int bfdopen(struct bfd *f) int bfdopen(struct bfd *f)
...@@ -104,10 +104,10 @@ static int brefill(struct bfd *f) ...@@ -104,10 +104,10 @@ static int brefill(struct bfd *f)
int ret; int ret;
struct xbuf *b = &f->b; struct xbuf *b = &f->b;
memmove(b->mem, b->pos, b->bleft); memmove(b->mem, b->data, b->sz);
b->pos = b->mem; 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) { if (ret < 0) {
pr_perror("bfd: Error reading file"); pr_perror("bfd: Error reading file");
return -1; return -1;
...@@ -116,7 +116,7 @@ static int brefill(struct bfd *f) ...@@ -116,7 +116,7 @@ static int brefill(struct bfd *f)
if (ret == 0) if (ret == 0)
return 0; return 0;
b->bleft += ret; b->sz += ret;
return 0; return 0;
} }
...@@ -138,19 +138,19 @@ char *breadline(struct bfd *f) ...@@ -138,19 +138,19 @@ char *breadline(struct bfd *f)
unsigned int ss = 0; unsigned int ss = 0;
again: again:
n = strnchr(b->pos + ss, b->bleft - ss, '\n'); n = strnchr(b->data + ss, b->sz - ss, '\n');
if (n) { if (n) {
char *ret; char *ret;
ret = b->pos; ret = b->data;
b->pos = n + 1; /* skip the \n found */ b->data = n + 1; /* skip the \n found */
*n = '\0'; *n = '\0';
b->bleft -= (b->pos - ret); b->sz -= (b->data - ret);
return ret; return ret;
} }
if (refilled) { if (refilled) {
if (!b->bleft) if (!b->sz)
return NULL; return NULL;
/* /*
...@@ -158,24 +158,24 @@ again: ...@@ -158,24 +158,24 @@ again:
* end, need to report this as full * end, need to report this as full
* line anyway * 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 * but we say that no bytes left there
* so next call to breadline will not * so next call to breadline will not
* "find" these bytes again. * "find" these bytes again.
*/ */
b->bleft = 0; b->sz = 0;
return b->pos; 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 * symols already, no need to re-scan them after
* the buffer refill. * the buffer refill.
*/ */
ss = b->bleft; ss = b->sz;
/* no full line in the buffer -- refill one */ /* no full line in the buffer -- refill one */
if (brefill(f)) if (brefill(f))
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
struct bfd_buf; struct bfd_buf;
struct xbuf { struct xbuf {
char *mem; /* buffer */ char *mem; /* buffer */
char *pos; /* position we see bytes at */ char *data; /* position we see bytes at */
unsigned int bleft; /* bytes left after b->pos */ unsigned int sz; /* bytes sitting after b->pos */
struct bfd_buf *buf; struct bfd_buf *buf;
}; };
......
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