File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,6 +46,15 @@ extern int deflateEnd(z_stream *strm);
4646#define O_NOFOLLOW 0
4747#endif
4848
49+ /* Ensure O_BINARY is available for binary-safe extraction on Windows. */
50+ #ifndef O_BINARY
51+ #ifdef _O_BINARY
52+ #define O_BINARY _O_BINARY
53+ #else
54+ #define O_BINARY 0
55+ #endif
56+ #endif
57+
4958#ifdef _WIN32
5059#include <direct.h>
5160#include <io.h>
@@ -490,7 +499,7 @@ static int extract_all(const char *path) {
490499 * stdio buffering issues. */
491500 int fd = -1 ;
492501 int open_flags = O_WRONLY | O_CREAT | O_EXCL ;
493- fd = open (fname_sanitized , open_flags , desired_mode );
502+ fd = open (fname_sanitized , open_flags | O_BINARY , desired_mode );
494503 if (fd < 0 ) {
495504 if (errno == EEXIST ) {
496505 if (!g_force ) {
@@ -504,7 +513,7 @@ static int extract_all(const char *path) {
504513 zip_fclose (zf );
505514 continue ;
506515 }
507- fd = open (fname_sanitized , O_WRONLY | O_TRUNC | O_NOFOLLOW );
516+ fd = open (fname_sanitized , O_WRONLY | O_TRUNC | O_NOFOLLOW | O_BINARY );
508517 if (fd < 0 ) {
509518 fprintf (stderr , "Cannot open for overwrite %s: %s\n" , fname_sanitized , strerror (errno ));
510519 zip_fclose (zf );
You can’t perform that action at this time.
0 commit comments