Skip to contentSkip to conversation

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

PATCH In review Jamey Sharp 2 participants 2 messages May 16, 2008 – May 21, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Open slurped files in binary mode, on systems where that matters.

---
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(-)
kexec/kexec.c +5 -2
index de9765e..1da6c1e 100644
@@ -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));
Signature · 7 lines
1.5.4.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 4 lines · Jamey Sharp

---
This patch shouldn't hurt any system that doesn't distinguish between binary and text files, and helps when running on Windows.

Thanks,

I have to confess that I've never had to deal with _O_BINARY myself, but the patch does look correct to me. I have applied it.

Signature · 7 lines
Horms


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec