From 857fa4426bcdd0236016de462956b4716682ccab Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 20 Nov 2013 18:57:18 +0100 Subject: [PATCH] Hack libzip into building on win32 --- ext/libzip/config.h | 6 +- ext/libzip/mkstemp.c | 17 ++- ext/libzip/zip.h | 12 +- ext/libzip/zip_close.c | 9 +- ext/libzip/zipint.h | 12 +- native.vcxproj | 328 ++++++++++++++++++++++++++++++++++++++++- native.vcxproj.filters | 173 +++++++++++++++++++++- 7 files changed, 544 insertions(+), 13 deletions(-) diff --git a/ext/libzip/config.h b/ext/libzip/config.h index 5503d4e4b5..e202a3d91f 100644 --- a/ext/libzip/config.h +++ b/ext/libzip/config.h @@ -22,7 +22,9 @@ #define HAVE_MEMORY_H 0 /* Define to 1 if you have the `mkstemp' function. */ -#define HAVE_MKSTEMP 0 +#ifndef _WIN32 +#define HAVE_MKSTEMP 1 +#endif /* Define to 1 if you have the `MoveFileExA' function. */ /* #undef HAVE_MOVEFILEEXA */ @@ -40,7 +42,7 @@ #define HAVE_STRING_H 1 /* Define to 1 if `tm_zone' is a member of `struct tm'. */ -#define HAVE_STRUCT_TM_TM_ZONE 1 +// #define HAVE_STRUCT_TM_TM_ZONE 0 /* Define to 1 if you have the header file. */ #define HAVE_SYS_STAT_H 1 diff --git a/ext/libzip/mkstemp.c b/ext/libzip/mkstemp.c index 738a065a09..e8a749fceb 100644 --- a/ext/libzip/mkstemp.c +++ b/ext/libzip/mkstemp.c @@ -43,6 +43,11 @@ #include #include +#ifdef _WIN32 +typedef int pid_t; +#define getpid rand +#endif + #ifndef O_BINARY #define O_BINARY 0 #endif @@ -60,7 +65,8 @@ _zip_mkstemp(char *path) /* To guarantee multiple calls generate unique names even if the file is not created. 676 different possibilities with 7 or more X's, 26 with 6 or less. */ - static char xtra[2] = "aa"; + // Urgh, not threadsafe at all. + static char xtra[3] = "aa"; int xcnt = 0; pid = getpid(); @@ -106,15 +112,22 @@ _zip_mkstemp(char *path) *trv = '\0'; if (stat(path, &sbuf)) return (0); +#ifndef _WIN32 if (!S_ISDIR(sbuf.st_mode)) { errno = ENOTDIR; return (0); } +#endif *trv = '/'; break; } } + +#ifdef _WIN32 + return 0; +#else + for (;;) { if ((fd=open(path, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600)) >= 0) return (fd); @@ -136,5 +149,7 @@ _zip_mkstemp(char *path) } } } +#endif + /*NOTREACHED*/ } diff --git a/ext/libzip/zip.h b/ext/libzip/zip.h index 48431a35c9..1798051de0 100644 --- a/ext/libzip/zip.h +++ b/ext/libzip/zip.h @@ -36,13 +36,19 @@ -#ifndef ZIP_EXTERN #ifdef _MSC_VER -#define ZIP_EXTERN __declspec(dllexport) +#ifndef ZIP_EXTERN +#define ZIP_EXTERN +// __declspec(dllexport) +#endif +#ifdef _M_X64 +typedef __int64 ssize_t; +#else +typedef __int32 ssize_t; +#endif #else #define ZIP_EXTERN #endif -#endif #ifdef __cplusplus extern "C" { diff --git a/ext/libzip/zip_close.c b/ext/libzip/zip_close.c index c6885d96a9..60614c6133 100644 --- a/ext/libzip/zip_close.c +++ b/ext/libzip/zip_close.c @@ -115,7 +115,7 @@ zip_close(struct zip *za) /* archive comment is special for torrentzip */ if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0)) { - cd->comment = _zip_memdup(TORRENT_SIG "XXXXXXXX", + cd->comment = (char *)_zip_memdup(TORRENT_SIG "XXXXXXXX", TORRENT_SIG_LEN + TORRENT_CRC_LEN, &za->error); if (cd->comment == NULL) { @@ -591,14 +591,14 @@ static int _zip_cdir_set_comment(struct zip_cdir *dest, struct zip *src) { if (src->ch_comment_len != -1) { - dest->comment = _zip_memdup(src->ch_comment, + dest->comment = (char *)_zip_memdup(src->ch_comment, src->ch_comment_len, &src->error); if (dest->comment == NULL) return -1; dest->comment_len = src->ch_comment_len; } else { if (src->cdir && src->cdir->comment) { - dest->comment = _zip_memdup(src->cdir->comment, + dest->comment = (char *)_zip_memdup(src->cdir->comment, src->cdir->comment_len, &src->error); if (dest->comment == NULL) return -1; @@ -636,7 +636,6 @@ _zip_changed(struct zip *za, int *survivorsp) } - static char * _zip_create_temp_output(struct zip *za, FILE **outp) { @@ -659,7 +658,9 @@ _zip_create_temp_output(struct zip *za, FILE **outp) if ((tfp=fdopen(tfd, "r+b")) == NULL) { _zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno); +#ifndef _WIN32 close(tfd); +#endif remove(temp); free(temp); return NULL; diff --git a/ext/libzip/zipint.h b/ext/libzip/zipint.h index f5a81b1934..287fd15550 100644 --- a/ext/libzip/zipint.h +++ b/ext/libzip/zipint.h @@ -37,7 +37,17 @@ #include #ifdef _MSC_VER -#define ZIP_EXTERN __declspec(dllimport) +#define ZIP_EXTERN +#define fseeko fseek +#define ftello ftell +#define snprintf _snprintf +#ifndef strcasecmp +#define strcasecmp _stricmp +#endif +#define umask(x) 0; +#define chmod(...) ; +typedef int mode_t; +// __declspec(dllimport) #endif #include "zip.h" diff --git a/native.vcxproj b/native.vcxproj index 0bdf5674f1..8b11cac105 100644 --- a/native.vcxproj +++ b/native.vcxproj @@ -206,6 +206,8 @@ + + @@ -342,6 +344,330 @@ + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + CompileAsCpp + @@ -410,4 +736,4 @@ - + \ No newline at end of file diff --git a/native.vcxproj.filters b/native.vcxproj.filters index c3e2b2e4ea..fe60f02013 100644 --- a/native.vcxproj.filters +++ b/native.vcxproj.filters @@ -289,6 +289,12 @@ gfx + + ext\libzip + + + ext\libzip + @@ -522,6 +528,168 @@ util + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + + + ext\libzip + @@ -587,5 +755,8 @@ {02e8ef95-82c7-4420-b029-a189a5e0fcbd} + + {aa8b9b49-2ff8-4961-b6cc-9c33ea674130} + - + \ No newline at end of file