summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorScott Duplichan <scott@notabs.org>2014-12-12 21:03:06 -0600
committerStefan Reinauer <stefan.reinauer@coreboot.org>2014-12-19 18:55:48 +0100
commitf2c9837e6f30e65f0a53b1c53c328ef8b6bf71f4 (patch)
tree19dc1377f3a4b771f7c2a2feed771a720503464d /util
parente1a4dc803ac9e0a34eabb8f5a7bbbde0c3fdf856 (diff)
downloadcoreboot-f2c9837e6f30e65f0a53b1c53c328ef8b6bf71f4.tar.xz
ifdtool: Add O_BINARY to open flags for Windows compatibility
Windows requires O_BINARY when opening a binary file. Otherwise \n characters get expanded to \r\n and <ctrl>z is treated as end of file. For compatibility with non-Windows hosts, the patch defines O_BINARY if it is not already defined. Change-Id: I04cd609b644b1edbe9104153b43b9996811ffd38 Signed-off-by: Scott Duplichan <scott@notabs.org> Reviewed-on: http://review.coreboot.org/7789 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Diffstat (limited to 'util')
-rw-r--r--util/ifdtool/ifdtool.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index 625d650a5e..9569dfa4ef 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -27,6 +27,10 @@
#include <sys/stat.h>
#include "ifdtool.h"
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#define NUM_REGIONS 5
static const struct region_name region_names[NUM_REGIONS] = {
@@ -538,7 +542,7 @@ static void write_regions(char *image, int size)
if (region.size > 0) {
int region_fd;
region_fd = open(region_filename(i),
- O_WRONLY | O_CREAT | O_TRUNC,
+ O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (region_fd < 0) {
perror("Error while trying to open file");
@@ -564,7 +568,7 @@ static void write_image(char *filename, char *image, int size)
// Now write out new image
new_fd = open(new_filename,
- O_WRONLY | O_CREAT | O_TRUNC,
+ O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (new_fd < 0) {
perror("Error while trying to open file");
@@ -643,7 +647,7 @@ void inject_region(char *filename, char *image, int size, int region_type,
exit(EXIT_FAILURE);
}
- int region_fd = open(region_fname, O_RDONLY);
+ int region_fd = open(region_fname, O_RDONLY | O_BINARY);
if (region_fd == -1) {
perror("Could not open file");
exit(EXIT_FAILURE);
@@ -1060,7 +1064,7 @@ int main(int argc, char *argv[])
}
char *filename = argv[optind];
- int bios_fd = open(filename, O_RDONLY);
+ int bios_fd = open(filename, O_RDONLY | O_BINARY);
if (bios_fd == -1) {
perror("Could not open file");
exit(EXIT_FAILURE);