From: Alexander Dahl Date: Fri, 20 Apr 2018 13:29:30 +0000 (+0200) Subject: tools: mkenvimage: Fix read() stdin error handling X-Git-Tag: v2018.05-rc3~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3559028cb2840cc283652f4b7e4e1b457e6ec6a5;p=u-boot tools: mkenvimage: Fix read() stdin error handling 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 --- diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c index 8eee72e257..716cb73a5c 100644 --- a/tools/mkenvimage.c +++ b/tools/mkenvimage.c @@ -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;