[PATCH] filetype: Make it work on files < 512 bytes

Sascha Hauer s.hauer at pengutronix.de
Tue Apr 17 03:57:42 EDT 2012


This is a brown paper bag type of bugs. Do not assume that a file
has to be at minimun 512 bytes to be detectable.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/filetype.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 4b5a6fa..15a3732 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -92,10 +92,10 @@ enum filetype file_name_detect_type(const char *filename)
 	if (fd < 0)
 		return fd;
 
-	buf = xmalloc(512);
+	buf = xzalloc(512);
 
 	ret = read(fd, buf, 512);
-	if (ret != 512)
+	if (ret < 0)
 		goto err_out;
 
 	type = file_detect_type(buf);
-- 
1.7.10




More information about the barebox mailing list