[PATCH] Open slurped files in binary mode, on systems where that matters.

Jamey Sharp jamey at thetovacompany.com
Thu May 15 20:13:37 EDT 2008


Signed-off-by: Jamey Sharp <jamey at thetovacompany.com>
---
This patch shouldn't hurt any system that doesn't distinguish between
binary and text files, and helps when running on Windows.

 kexec/kexec.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index de9765e..1da6c1e 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -30,6 +30,9 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifndef _O_BINARY
+#define _O_BINARY 0
+#endif
 #include <getopt.h>
 
 #include "config.h"
@@ -386,7 +389,7 @@ char *slurp_file(const char *filename, off_t *r_size)
 		*r_size = 0;
 		return 0;
 	}
-	fd = open(filename, O_RDONLY);
+	fd = open(filename, O_RDONLY | _O_BINARY);
 	if (fd < 0) {
 		die("Cannot open `%s': %s\n",
 			filename, strerror(errno));
@@ -431,7 +434,7 @@ char *slurp_file_len(const char *filename, off_t size)
 
 	if (!filename)
 		return 0;
-	fd = open(filename, O_RDONLY);
+	fd = open(filename, O_RDONLY | _O_BINARY);
 	if (fd < 0) {
 		fprintf(stderr, "Cannot open %s: %s\n", filename,
 				strerror(errno));
-- 
1.5.4.1




More information about the kexec mailing list