diff mbox series

[U-Boot,1/2] tools: mkenvimage: Fix read() stdin error handling

Message ID 20180420132931.22250-2-ada@thorsis.com
State Accepted
Commit 3559028cb2840cc283652f4b7e4e1b457e6ec6a5
Delegated to: Tom Rini
Headers show
Series tools: mkenvimage: Fix input from STDIN | expand

Commit Message

Alexander Dahl April 20, 2018, 1:29 p.m. UTC
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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tom Rini April 29, 2018, 9:04 p.m. UTC | #1
On Fri, Apr 20, 2018 at 03:29:30PM +0200, Alexander Dahl wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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;