2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-02 07:15:31 +00:00

Introduce the read_into_buffer helper

This will be required for page-cache and page-proxy set.

Signed-off-by: Rodrigo Bruno <rbruno at gsd.inesc-id.pt>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Rodrigo Bruno
2015-12-12 01:18:00 +03:00
committed by Pavel Emelyanov
parent 391efc9d7e
commit 91b689a3a4
2 changed files with 16 additions and 0 deletions

View File

@@ -267,6 +267,7 @@ FILE *fopenat(int dirfd, char *path, char *cflags);
void split(char *str, char token, char ***out, int *n); void split(char *str, char token, char ***out, int *n);
int fd_has_data(int lfd); int fd_has_data(int lfd);
size_t read_into_buffer(int fd, char *buff, size_t size);
int make_yard(char *path); int make_yard(char *path);

15
util.c
View File

@@ -872,6 +872,21 @@ int fd_has_data(int lfd)
return ret; return ret;
} }
size_t read_into_buffer(int fd, char *buff, size_t size)
{
size_t n = 0;
size_t curr = 0;
while (1) {
n = read(fd, buff + curr, size - curr);
if (n < 1)
return n;
curr += n;
if (curr == size)
return size;
}
}
int make_yard(char *path) int make_yard(char *path)
{ {
if (mount("none", path, "tmpfs", 0, NULL)) { if (mount("none", path, "tmpfs", 0, NULL)) {