} else
mine->can_skip = 0;
+#if defined(_WIN32_)
+ _setmode(mine->fd, _O_BINARY);
+#endif
+
return (archive_read_open2(a, mine,
NULL, file_read, file_skip, file_close));
}
} else
mine->can_skip = 0;
+#if defined(_WIN32_)
+ _setmode(_fileno(mine->f), _O_BINARY);
+#endif
+
return (archive_read_open2(a, mine, NULL, file_read,
file_skip, file_close));
}
*/
filename = ""; /* Normalize NULL to "" */
fd = 0;
+#if defined(_WIN32_)
+ _setmode(0, _O_BINARY);
+#endif
} else {
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
fprintf(stderr, "%s:%d: File not empty: %s\n", test_filename, test_line, f1);
fprintf(stderr, " File size: %d\n", (int)st.st_size);
fprintf(stderr, " Contents:\n");
- fd = open(f1, O_RDONLY);
+ fd = open(f1, O_RDONLY | O_BINARY);
if (fd < 0) {
fprintf(stderr, " Unable to open %s\n", f1);
} else {
vsprintf(f2, f2pattern, ap);
va_end(ap);
- fd1 = open(f1, O_RDONLY);
- fd2 = open(f2, O_RDONLY);
+ fd1 = open(f1, O_RDONLY | O_BINARY);
+ fd2 = open(f2, O_RDONLY | O_BINARY);
for (;;) {
n1 = read(fd1, buff1, sizeof(buff1));
n2 = read(fd2, buff2, sizeof(buff2));
vsprintf(f, fpattern, ap);
va_end(ap);
- fd = open(f, O_RDONLY);
+ fd = open(f, O_RDONLY | O_BINARY);
contents = malloc(s * 2);
n = read(fd, contents, s * 2);
if (n == s && memcmp(buff, contents, s) == 0) {
vsprintf(filename, fmt, ap);
va_end(ap);
- fd = open(filename, O_RDONLY);
+ fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
/* Note: No error; non-existent file is okay here. */
return (NULL);
}
/* Now, decode the rest and write it. */
/* Not a lot of error checking here; the input better be right. */
- out = fopen(name, "w");
+ out = fopen(name, "wb");
while (fgets(buff, sizeof(buff), in) != NULL) {
char *p = buff;
int bytes;
/* To stop to run the default invalid parameter handler. */
_set_invalid_parameter_handler(invalid_parameter_handler);
/* for open() to a binary mode. */
- _set_fmode(_O_BINARY);
+ /* This shouldn't be needed, because all tests should
+ * explicitly use O_BINARY flag to open() and "b" to
+ * fopen(): */
+ /* _set_fmode(_O_BINARY); */
/* Disable annoying assertion message box. */
_CrtSetReportMode(_CRT_ASSERT, 0);
#endif
acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx");
assert((void *)acl != NULL);
/* Create a test file and try to set an ACL on it. */
- fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777);
+ fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0777);
failure("Could not create test file?!");
if (!assert(fd >= 0)) {
acl_free(acl);
#endif
/* Write out the data we generated to a file for manual inspection. */
- assert(-1 < (fd = open("testout", O_WRONLY | O_CREAT | O_TRUNC, 0775)));
+ assert(-1 < (fd = open("testout",
+ O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0775)));
assert(used == (size_t)write(fd, buff, (unsigned int)used));
close(fd);
/* Write out the reference data to a file for manual inspection. */
- assert(-1 < (fd = open("reference", O_WRONLY | O_CREAT | O_TRUNC, 0775)));
+ assert(-1 < (fd = open("reference",
+ O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0775)));
assert(sizeof(reference) == write(fd, reference, sizeof(reference)));
close(fd);
* doesn't, we'll simply skip the remaining tests.
*/
/* Create a test file and try to set an ACL on it. */
- fd = open("pretest", O_RDWR | O_CREAT, 0777);
+ fd = open("pretest", O_RDWR | O_CREAT | O_BINARY, 0777);
failure("Could not create test file?!");
if (!assert(fd >= 0))
return;
* permissions, not file permissions), but is known broken on
* some versions of FreeBSD.
*/
- fd = open("pretest2", O_RDWR | O_CREAT, 00000);
+ fd = open("pretest2", O_RDWR | O_CREAT | O_BINARY, 00000);
failure("Could not create test file?!");
if (!assert(fd >= 0))
return;
* If we crash, that file will be useful. */
fd = open("after.test.failure.send.this.file."
"to.libarchive.maintainers.with.system.details",
- O_WRONLY | O_CREAT | O_TRUNC, 0744);
+ O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0744);
write(fd, image, (off_t)size);
close(fd);
struct archive *a;
int fd;
- fd = open("test.tar", O_RDWR | O_CREAT, 0777);
+ fd = open("test.tar", O_RDWR | O_CREAT | O_BINARY, 0777);
assert(fd >= 0);
if (fd < 0)
return;
struct archive *a;
FILE *f;
- f = fopen("test.tar", "w");
+ f = fopen("test.tar", "wb");
assert(f != NULL);
if (f == NULL)
return;
/*
* Now, read the data back.
*/
- f = fopen("test.tar", "r");
+ f = fopen("test.tar", "rb");
assert(f != NULL);
if (f == NULL)
return;
assertA(0 == archive_read_support_compression_all(a));
assertA(0 == archive_read_open_memory(a, buff1, sizeof(buff1)));
assertA(0 == archive_read_next_header(a, &ae));
- tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT, 0777);
+ tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY, 0777);
assert(tmpfilefd != 0);
assertEqualIntA(a, 0, archive_read_data_into_fd(a, tmpfilefd));
assert(0 == archive_read_close(a));
#endif
close(tmpfilefd);
- tmpfilefd = open(tmpfilename, O_RDONLY);
+ tmpfilefd = open(tmpfilename, O_RDONLY | O_BINARY);
assert(tmpfilefd != 0);
assertEqualIntA(NULL, sizeof(buff3), read(tmpfilefd, buff3, sizeof(buff3)));
close(tmpfilefd);
assertEqualString(archive_read_disk_gname(a, 0), "FOOGROUP");
/* Create a file on disk. */
- fd = open("foo", O_WRONLY | O_CREAT, 0777);
+ fd = open("foo", O_WRONLY | O_CREAT | O_BINARY, 0777);
assert(fd >= 0);
assertEqualInt(4, write(fd, "1234", 4));
close(fd);
assertEqualInt(st.st_mode, S_IFREG | 0755);
failure("The file extracted to disk is the wrong size.");
assert(st.st_size == FILE_BUFF_SIZE);
- fd = open("file", O_RDONLY);
+ fd = open("file", O_RDONLY | O_BINARY);
failure("The file on disk could not be opened.");
assert(fd != 0);
bytes_read = read(fd, buff, FILE_BUFF_SIZE);
/*
* Read "file", whose data is available on disk.
*/
- fd = open("file", O_WRONLY | O_CREAT, 0777);
+ fd = open("file", O_WRONLY | O_CREAT | O_BINARY, 0777);
assert(fd >= 0);
assertEqualInt(3, write(fd, "hi\n", 3));
close(fd);
assertA(0 == archive_read_support_compression_all(a));
assertA(0 == archive_read_open_memory(a, buff, sizeof(buff)));
assertA(0 == archive_read_next_header(a, &entry));
- assert(0 < (tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY, 0755)));
+ assert(0 < (tmpfilefd = open(tmpfilename,
+ O_WRONLY | O_CREAT | O_BINARY, 0755)));
assertA(0 == archive_read_data_into_fd(a, tmpfilefd));
close(tmpfilefd);
#if ARCHIVE_VERSION_NUMBER < 2000000
#else
assertA(0 == archive_read_finish(a));
#endif
- tmpfilefd = open(tmpfilename, O_RDONLY);
+ tmpfilefd = open(tmpfilename, O_RDONLY | O_BINARY);
read(tmpfilefd, testdatacopy, sizeof(testdatacopy));
close(tmpfilefd);
assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata)));
assertEqualInt(st.st_size, i);
compare = malloc(datasize);
- fd = open(archive_entry_pathname(ae), O_RDONLY);
+ fd = open(archive_entry_pathname(ae), O_RDONLY | O_BINARY);
assertEqualInt(datasize, read(fd, compare, datasize));
close(fd);
assert(memcmp(compare, data, datasize) == 0);
assertEqualInt(0, mkdir("dir", 0555));
/* Can we? */
- fd = open("dir/testfile", O_WRONLY | O_CREAT, 0777);
+ fd = open("dir/testfile", O_WRONLY | O_CREAT | O_BINARY, 0777);
if (fd >= 0) {
/* Apparently, we can, so the test below won't work. */
close(fd);
_searched = 1;
/* Create a file on disk in the current default dir. */
- fd = open("test_gid", O_CREAT, 0664);
+ fd = open("test_gid", O_CREAT | O_BINARY, 0664);
failure("Couldn't create a file for gid testing.");
assert(fd > 0);
/* Test the entry on disk. */
assert(0 == stat(archive_entry_pathname(ae), &st));
assertEqualInt(st.st_size, 8 * buff_size);
- fd = open(archive_entry_pathname(ae), O_RDONLY);
+ fd = open(archive_entry_pathname(ae), O_RDONLY | O_BINARY);
if (!assert(fd >= 0))
return;
/* Test the entry on disk. */
assert(0 == stat(archive_entry_pathname(ae), &st));
assertEqualInt(st.st_size, 8 * buff_size);
- fd = open(archive_entry_pathname(ae), O_RDONLY);
+ fd = open(archive_entry_pathname(ae), O_RDONLY | O_BINARY);
if (!assert(fd >= 0))
return;