]> git.sur5r.net Git - u-boot/commitdiff
tools: mkenvimage: Fix read() stdin error handling
authorAlexander Dahl <ada@thorsis.com>
Fri, 20 Apr 2018 13:29:30 +0000 (15:29 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 28 Apr 2018 22:32:24 +0000 (18:32 -0400)
On success read() returns the number of bytes read or zero for EOF. On
error -1 is returned and errno is set, so the right way to test if read
had failed is to test the return value instead of errno.

Signed-off-by: Alexander Dahl <ada@thorsis.com>
tools/mkenvimage.c

index 8eee72e2572e321bbcf70d516d884708724f7fa4..716cb73a5c63b70d18943e0e9629eb22d9c5965b 100644 (file)
@@ -168,7 +168,7 @@ int main(int argc, char **argv)
                                return EXIT_FAILURE;
                        }
                        readbytes = read(txt_fd, filebuf + filesize, readlen);
-                       if (errno) {
+                       if (readbytes < 0) {
                                fprintf(stderr, "Error while reading stdin: %s\n",
                                                strerror(errno));
                                return EXIT_FAILURE;