mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-08-04 15:53:44 +00:00
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: Pavel Emelyanov <xemul@parallels.com> Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
parent
166c58d5bb
commit
67bbc7ea0b
2 changed files with 20 additions and 20 deletions
36
bfd.c
36
bfd.c
|
|
@ -63,8 +63,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 %p <\n", xb->mem);
|
||||
return 0;
|
||||
|
|
@ -80,7 +80,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)
|
||||
|
|
@ -104,10 +104,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;
|
||||
|
|
@ -116,7 +116,7 @@ static int brefill(struct bfd *f)
|
|||
if (ret == 0)
|
||||
return 0;
|
||||
|
||||
b->bleft += ret;
|
||||
b->sz += ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -138,19 +138,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;
|
||||
|
||||
/*
|
||||
|
|
@ -158,24 +158,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))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue