Skip to content

Commit 0d5abac

Browse files
committed
Need to use O_BINARY if it exists (i.e. on Windows).
1 parent 7620535 commit 0d5abac

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cocofs.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
#include <string.h>
8686
#include <unistd.h>
8787

88+
/* We need to use O_BINARY on platforms that have it (Windows). */
89+
#ifndef O_BINARY
90+
#define O_BINARY 0
91+
#endif
92+
8893
/*
8994
* Format information is gleaned from:
9095
*
@@ -947,7 +952,7 @@ cocofs_copyout(const struct cocofs *fs, const struct cocofs_dirent *dir,
947952
uint8_t g, gn;
948953
int outfd;
949954

950-
outfd = open(outfname, O_WRONLY | O_CREAT, 0644);
955+
outfd = open(outfname, O_WRONLY | O_CREAT | O_BINARY, 0644);
951956
if (outfd == -1) {
952957
fprintf(stderr, "unable to open output file %s: %s\n",
953958
outfname, strerror(errno));
@@ -1067,7 +1072,7 @@ cocofs_copyin(struct cocofs *fs, const char *infile, const char name[8],
10671072
*/
10681073
memset(glist, 0xff, sizeof(glist));
10691074

1070-
infd = open(infile, O_RDONLY);
1075+
infd = open(infile, O_RDONLY | O_BINARY);
10711076
if (infd == -1) {
10721077
fprintf(stderr,
10731078
"unable to open %s: %s\n", infile, strerror(errno));
@@ -1486,7 +1491,7 @@ main(int argc, char *argv[])
14861491
}
14871492

14881493
/* Open the image (name in argv[0]). */
1489-
fd = open(argv[0], cmdtab[cmd].oflags, 0644);
1494+
fd = open(argv[0], cmdtab[cmd].oflags | O_BINARY, 0644);
14901495
if (fd == -1) {
14911496
fprintf(stderr, "ERROR: failed to open '%s': %s\n",
14921497
argv[0], strerror(errno));

0 commit comments

Comments
 (0)