From 2866e9d5d00f0a0c7c7d4344d5a2b09a1dd97c7e Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Mon, 28 Dec 2009 02:28:44 +0000 Subject: [PATCH] Portability: Set the file descriptor to binary mode on Win32 --- lib/libarchive/archive_read_open_file.c | 7 +++++++ lib/libarchive/archive_read_open_filename.c | 6 ++++++ lib/libarchive/archive_write_open_fd.c | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/libarchive/archive_read_open_file.c b/lib/libarchive/archive_read_open_file.c index 37039e95a111..1575f94ca443 100644 --- a/lib/libarchive/archive_read_open_file.c +++ b/lib/libarchive/archive_read_open_file.c @@ -35,6 +35,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_FCNTL_H #include #endif +#ifdef HAVE_IO_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif @@ -94,6 +97,10 @@ archive_read_open_FILE(struct archive *a, FILE *f) } else mine->can_skip = 0; +#if defined(__CYGWIN__) || defined(_WIN32) + setmode(fileno(mine->f), O_BINARY); +#endif + return (archive_read_open2(a, mine, NULL, file_read, file_skip, file_close)); } diff --git a/lib/libarchive/archive_read_open_filename.c b/lib/libarchive/archive_read_open_filename.c index 64a89b52b3c9..ec0bb369e036 100644 --- a/lib/libarchive/archive_read_open_filename.c +++ b/lib/libarchive/archive_read_open_filename.c @@ -35,6 +35,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_FCNTL_H #include #endif +#ifdef HAVE_IO_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif @@ -96,6 +99,9 @@ archive_read_open_filename(struct archive *a, const char *filename, */ filename = ""; /* Normalize NULL to "" */ fd = 0; +#if defined(__CYGWIN__) || defined(_WIN32) + setmode(0, O_BINARY); +#endif } else { fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) { diff --git a/lib/libarchive/archive_write_open_fd.c b/lib/libarchive/archive_write_open_fd.c index f4cc6ac1c54e..b0793a26bc89 100644 --- a/lib/libarchive/archive_write_open_fd.c +++ b/lib/libarchive/archive_write_open_fd.c @@ -32,6 +32,12 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_ERRNO_H #include #endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_IO_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif @@ -64,6 +70,9 @@ archive_write_open_fd(struct archive *a, int fd) return (ARCHIVE_FATAL); } mine->fd = fd; +#if defined(__CYGWIN__) || defined(_WIN32) + setmode(mine->fd, O_BINARY); +#endif return (archive_write_open(a, mine, file_open, file_write, file_close)); }