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 <[email protected]>
---
 util.c |   25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

--- dmidecode.orig/util.c       2018-08-01 10:40:07.043544869 +0200
+++ dmidecode/util.c    2018-08-01 10:47:29.231481728 +0200
@@ -99,8 +99,6 @@ void *read_file(off_t base, size_t *max_
 {
        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_
                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);
 

-- 
Jean Delvare
SUSE L3 Support

_______________________________________________
https://lists.nongnu.org/mailman/listinfo/dmidecode-devel

Reply via email to