Files in sysfs or procfs may be smaller than st_size actually reports. We will read file from sysfs in future.
This patch makes the strong assumption that the st_size field in struct stat can be seen as an upper bound for the actual file content. Signed-off-by: Ralf Ramsauer <[email protected]> --- tools/jailhouse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/jailhouse.c b/tools/jailhouse.c index be5b833..ae2ed3f 100644 --- a/tools/jailhouse.c +++ b/tools/jailhouse.c @@ -128,6 +128,7 @@ static void *read_string(const char *string, size_t *size) static void *read_file(const char *name, size_t *size) { struct stat stat; + ssize_t result; void *buffer; int fd; @@ -148,7 +149,8 @@ static void *read_file(const char *name, size_t *size) exit(1); } - if (read(fd, buffer, stat.st_size) < stat.st_size) { + result = read(fd, buffer, stat.st_size); + if (result < 0) { fprintf(stderr, "reading %s: %s\n", name, strerror(errno)); exit(1); } @@ -156,7 +158,7 @@ static void *read_file(const char *name, size_t *size) close(fd); if (size) - *size = stat.st_size; + *size = (size_t)result; return buffer; } -- 2.9.3 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
