diff options
author | Jean Delvare <jdelvare@suse.de> | 2018-08-09 09:34:18 +0200 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2018-08-09 09:34:18 +0200 |
commit | 83a77865a13c5d73ee80beb9434019c0e01b16ac (patch) | |
tree | d6529dbbf45b67aba4ffb95f112fb406998bd4d4 /util.c | |
parent | 2818946fc800aaefa7fd25d52e45babd6db13d9b (diff) | |
download | dmidecode-git-83a77865a13c5d73ee80beb9434019c0e01b16ac.tar.gz |
util: Use myread() in read_file()
Now that we check the file size before reading, we no longer expect
to hit the end of file prematurely. This means we can call myread()
instead of reimplementing it, thus removing some code redundancy.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 25 |
1 files changed, 5 insertions, 20 deletions
@@ -99,8 +99,6 @@ void *read_file(off_t base, size_t *max_len, const char *filename) { struct stat statbuf; int fd; - size_t r2 = 0; - ssize_t r; u8 *p; /* @@ -137,25 +135,12 @@ void *read_file(off_t base, size_t *max_len, const char *filename) goto out; } - do - { - r = read(fd, p + r2, *max_len - r2); - if (r == -1) - { - if (errno != EINTR) - { - perror(filename); - free(p); - p = NULL; - goto out; - } - } - else - r2 += r; - } - while (r != 0); + if (myread(fd, p, *max_len, filename) == 0) + goto out; + + free(p); + p = NULL; - *max_len = r2; out: close(fd); |