|
85 | 85 | #include <string.h>
|
86 | 86 | #include <unistd.h>
|
87 | 87 |
|
| 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 | + |
88 | 93 | /*
|
89 | 94 | * Format information is gleaned from:
|
90 | 95 | *
|
@@ -947,7 +952,7 @@ cocofs_copyout(const struct cocofs *fs, const struct cocofs_dirent *dir,
|
947 | 952 | uint8_t g, gn;
|
948 | 953 | int outfd;
|
949 | 954 |
|
950 |
| - outfd = open(outfname, O_WRONLY | O_CREAT, 0644); |
| 955 | + outfd = open(outfname, O_WRONLY | O_CREAT | O_BINARY, 0644); |
951 | 956 | if (outfd == -1) {
|
952 | 957 | fprintf(stderr, "unable to open output file %s: %s\n",
|
953 | 958 | outfname, strerror(errno));
|
@@ -1067,7 +1072,7 @@ cocofs_copyin(struct cocofs *fs, const char *infile, const char name[8],
|
1067 | 1072 | */
|
1068 | 1073 | memset(glist, 0xff, sizeof(glist));
|
1069 | 1074 |
|
1070 |
| - infd = open(infile, O_RDONLY); |
| 1075 | + infd = open(infile, O_RDONLY | O_BINARY); |
1071 | 1076 | if (infd == -1) {
|
1072 | 1077 | fprintf(stderr,
|
1073 | 1078 | "unable to open %s: %s\n", infile, strerror(errno));
|
@@ -1486,7 +1491,7 @@ main(int argc, char *argv[])
|
1486 | 1491 | }
|
1487 | 1492 |
|
1488 | 1493 | /* 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); |
1490 | 1495 | if (fd == -1) {
|
1491 | 1496 | fprintf(stderr, "ERROR: failed to open '%s': %s\n",
|
1492 | 1497 | argv[0], strerror(errno));
|
|
0 commit comments