From 54904e02380cd05191458f4b99bef92308ca12c7 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Fri, 27 Mar 2020 16:25:36 +0100 Subject: [PATCH] WIP fix compilation for Universal Windows --- libarchive/archive_check_magic.c | 3 +- libarchive/archive_entry.h | 2 +- libarchive/archive_entry_copy_bhfi.c | 2 +- libarchive/archive_read_disk_windows.c | 9 ++++++ .../archive_read_support_filter_bzip2.c | 4 +++ .../archive_read_support_filter_grzip.c | 4 +++ .../archive_read_support_filter_lrzip.c | 4 +++ libarchive/archive_read_support_filter_lz4.c | 4 +++ libarchive/archive_read_support_filter_lzop.c | 4 +++ .../archive_read_support_filter_program.c | 14 ++++++--- libarchive/archive_read_support_filter_xz.c | 12 +++++++ libarchive/archive_read_support_filter_zstd.c | 4 +++ .../archive_read_support_format_mtree.c | 10 ++++++ libarchive/archive_string.c | 2 +- libarchive/archive_util.c | 9 +++++- libarchive/archive_windows.c | 31 ++++++++++++++++++- libarchive/archive_windows.h | 6 ++++ libarchive/filter_fork_windows.c | 8 +++++ 18 files changed, 121 insertions(+), 11 deletions(-) diff --git a/libarchive/archive_check_magic.c b/libarchive/archive_check_magic.c index 288ce233..3b3b9bc7 100644 --- a/libarchive/archive_check_magic.c +++ b/libarchive/archive_check_magic.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_check_magic.c 201089 2009-12-28 #if defined(_WIN32) && !defined(__CYGWIN__) #include #include +#include #endif #include "archive_private.h" @@ -65,7 +66,7 @@ errmsg(const char *m) static __LA_DEAD void diediedie(void) { -#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) && WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) /* Cause a breakpoint exception */ DebugBreak(); #endif diff --git a/libarchive/archive_entry.h b/libarchive/archive_entry.h index 42af2086..cff6e55a 100644 --- a/libarchive/archive_entry.h +++ b/libarchive/archive_entry.h @@ -303,7 +303,7 @@ __LA_DECL int archive_entry_is_encrypted(struct archive_entry *); __LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long); __LA_DECL void archive_entry_unset_atime(struct archive_entry *); -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) __LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, BY_HANDLE_FILE_INFORMATION *); #endif __LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long); diff --git a/libarchive/archive_entry_copy_bhfi.c b/libarchive/archive_entry_copy_bhfi.c index 77bf38e4..22f9702c 100644 --- a/libarchive/archive_entry_copy_bhfi.c +++ b/libarchive/archive_entry_copy_bhfi.c @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD$"); #include "archive_private.h" #include "archive_entry.h" -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) diff --git a/libarchive/archive_read_disk_windows.c b/libarchive/archive_read_disk_windows.c index fdd376f9..85215326 100644 --- a/libarchive/archive_read_disk_windows.c +++ b/libarchive/archive_read_disk_windows.c @@ -715,7 +715,11 @@ start_next_async_read(struct archive_read_disk *a, struct tree *t) if (olp->buff == NULL) { void *p; size_t s = (size_t)align_num_per_sector(t, READ_BUFFER_SIZE); +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) p = VirtualAlloc(NULL, s, MEM_COMMIT, PAGE_READWRITE); +#else /* !WINAPI_PARTITION_DESKTOP */ + p = VirtualAllocFromApp(NULL, s, MEM_COMMIT, PAGE_READWRITE); +#endif /* !WINAPI_PARTITION_DESKTOP */ if (p == NULL) { archive_set_error(&a->archive, ENOMEM, "Couldn't allocate memory"); @@ -1512,7 +1516,12 @@ setup_current_filesystem(struct archive_read_disk *a) t->current_filesystem->synthetic = -1;/* Not supported */ path = safe_path_for_statfs(t); +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) if (!GetVolumePathNameW(path, vol, sizeof(vol)/sizeof(vol[0]))) { +#else /* !WINAPI_PARTITION_DESKTOP */ + DWORD MaximumComponentLength, FileSystemFlags; + if (!GetVolumeInformationW(path, vol, sizeof(vol)/sizeof(vol[0]), NULL, &MaximumComponentLength, &FileSystemFlags, NULL, 0)) { +#endif free(path); t->current_filesystem->remote = -1; t->current_filesystem->bytesPerSector = 0; diff --git a/libarchive/archive_read_support_filter_bzip2.c b/libarchive/archive_read_support_filter_bzip2.c index 3885a7cf..d2e8b001 100644 --- a/libarchive/archive_read_support_filter_bzip2.c +++ b/libarchive/archive_read_support_filter_bzip2.c @@ -169,6 +169,7 @@ bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_fi static int bzip2_reader_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "bzip2 -d"); @@ -178,6 +179,9 @@ bzip2_reader_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_BZIP2; self->name = "bzip2"; return (r); +#else + return ARCHIVE_FATAL; +#endif } diff --git a/libarchive/archive_read_support_filter_grzip.c b/libarchive/archive_read_support_filter_grzip.c index 84c86aeb..66c32b4b 100644 --- a/libarchive/archive_read_support_filter_grzip.c +++ b/libarchive/archive_read_support_filter_grzip.c @@ -109,6 +109,7 @@ grzip_bidder_bid(struct archive_read_filter_bidder *self, static int grzip_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "grzip -d"); @@ -118,4 +119,7 @@ grzip_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_GRZIP; self->name = "grzip"; return (r); +#else + return ARCHIVE_FATAL; +#endif } diff --git a/libarchive/archive_read_support_filter_lrzip.c b/libarchive/archive_read_support_filter_lrzip.c index c82a8e2f..b4100b9a 100644 --- a/libarchive/archive_read_support_filter_lrzip.c +++ b/libarchive/archive_read_support_filter_lrzip.c @@ -120,6 +120,7 @@ lrzip_bidder_bid(struct archive_read_filter_bidder *self, static int lrzip_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "lrzip -d -q"); @@ -129,4 +130,7 @@ lrzip_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LRZIP; self->name = "lrzip"; return (r); +#else + return ARCHIVE_FATAL; +#endif } diff --git a/libarchive/archive_read_support_filter_lz4.c b/libarchive/archive_read_support_filter_lz4.c index 43ee6c2b..5d3baf91 100644 --- a/libarchive/archive_read_support_filter_lz4.c +++ b/libarchive/archive_read_support_filter_lz4.c @@ -204,6 +204,7 @@ lz4_reader_bid(struct archive_read_filter_bidder *self, static int lz4_reader_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "lz4 -d -q"); @@ -213,6 +214,9 @@ lz4_reader_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LZ4; self->name = "lz4"; return (r); +#else + return ARCHIVE_FATAL; +#endif } diff --git a/libarchive/archive_read_support_filter_lzop.c b/libarchive/archive_read_support_filter_lzop.c index a1c392f4..191688f4 100644 --- a/libarchive/archive_read_support_filter_lzop.c +++ b/libarchive/archive_read_support_filter_lzop.c @@ -160,6 +160,7 @@ lzop_bidder_bid(struct archive_read_filter_bidder *self, static int lzop_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "lzop -d"); @@ -169,6 +170,9 @@ lzop_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LZOP; self->name = "lzop"; return (r); +#else + return ARCHIVE_FATAL; +#endif } #else /* diff --git a/libarchive/archive_read_support_filter_program.c b/libarchive/archive_read_support_filter_program.c index b8bf1288..2197ed41 100644 --- a/libarchive/archive_read_support_filter_program.c +++ b/libarchive/archive_read_support_filter_program.c @@ -82,6 +82,8 @@ archive_read_support_filter_program(struct archive *a, const char *cmd) return (archive_read_support_filter_program_signature(a, cmd, NULL, 0)); } + #if !defined(_WIN32) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + /* * The bidder object stores the command and the signature to watch for. * The 'inhibit' entry here is used to ensure that unchecked filters never @@ -105,7 +107,7 @@ static int program_bidder_free(struct archive_read_filter_bidder *); */ struct program_filter { struct archive_string description; -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE child; #else pid_t child; @@ -254,7 +256,7 @@ child_stop(struct archive_read_filter *self, struct program_filter *state) state->waitpid_return = waitpid(state->child, &state->exit_status, 0); } while (state->waitpid_return == -1 && errno == EINTR); -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) CloseHandle(state->child); #endif state->child = 0; @@ -309,7 +311,7 @@ child_read(struct archive_read_filter *self, char *buf, size_t buf_len) struct program_filter *state = self->data; ssize_t ret, requested, avail; const char *p; -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) HANDLE handle = (HANDLE)_get_osfhandle(state->child_stdout); #endif @@ -317,7 +319,7 @@ child_read(struct archive_read_filter *self, char *buf, size_t buf_len) for (;;) { do { -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) /* Avoid infinity wait. * Note: If there is no data in the pipe, ReadFile() * called in read() never returns and so we won't @@ -516,3 +518,5 @@ program_filter_close(struct archive_read_filter *self) return (e); } + +#endif // !_WIN32 || WINAPI_PARTITION_DESKTOP diff --git a/libarchive/archive_read_support_filter_xz.c b/libarchive/archive_read_support_filter_xz.c index 11807cf6..856e08a5 100644 --- a/libarchive/archive_read_support_filter_xz.c +++ b/libarchive/archive_read_support_filter_xz.c @@ -754,6 +754,7 @@ xz_filter_close(struct archive_read_filter *self) static int lzma_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "lzma -d -qq"); @@ -763,11 +764,15 @@ lzma_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LZMA; self->name = "lzma"; return (r); +#else + return ARCHIVE_FATAL; +#endif } static int xz_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "xz -d -qq"); @@ -777,11 +782,15 @@ xz_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_XZ; self->name = "xz"; return (r); +#else + return ARCHIVE_FATAL; +#endif } static int lzip_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "lzip -d -q"); @@ -791,6 +800,9 @@ lzip_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_LZIP; self->name = "lzip"; return (r); +#else + return ARCHIVE_FATAL; +#endif } #endif /* HAVE_LZMA_H */ diff --git a/libarchive/archive_read_support_filter_zstd.c b/libarchive/archive_read_support_filter_zstd.c index c8bb36be..84859211 100644 --- a/libarchive/archive_read_support_filter_zstd.c +++ b/libarchive/archive_read_support_filter_zstd.c @@ -143,6 +143,7 @@ zstd_bidder_bid(struct archive_read_filter_bidder *self, static int zstd_bidder_init(struct archive_read_filter *self) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int r; r = __archive_read_program(self, "zstd -d -qq"); @@ -152,6 +153,9 @@ zstd_bidder_init(struct archive_read_filter *self) self->code = ARCHIVE_FILTER_ZSTD; self->name = "zstd"; return (r); +#else + return ARCHIVE_FATAL; +#endif } #else diff --git a/libarchive/archive_read_support_format_mtree.c b/libarchive/archive_read_support_format_mtree.c index 332944ac..8c647131 100644 --- a/libarchive/archive_read_support_format_mtree.c +++ b/libarchive/archive_read_support_format_mtree.c @@ -57,6 +57,8 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011 #include "archive_string.h" #include "archive_pack_dev.h" +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + #ifndef O_BINARY #define O_BINARY 0 #endif @@ -2023,3 +2025,11 @@ readline(struct archive_read *a, struct mtree *mtree, char **start, find_off = u - mtree->line.s; } } + +#else +int +archive_read_support_format_mtree(struct archive *_a) +{ + return ARCHIVE_OK; +} +#endif diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index c77dcf52..7942ff8b 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -1323,7 +1323,7 @@ free_sconv_object(struct archive_string_conv *sc) free(sc); } -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) static unsigned my_atoi(const char *p) { diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c index 659665a8..d526497f 100644 --- a/libarchive/archive_util.c +++ b/libarchive/archive_util.c @@ -209,7 +209,7 @@ __archive_errx(int retvalue, const char *msg) * Create a temporary file */ #if defined(_WIN32) && !defined(__CYGWIN__) - +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) /* * Do not use Windows tmpfile() function. * It will make a temporary file under the root directory @@ -378,6 +378,13 @@ exit_tmpfile: archive_wstring_free(&temp_name); return (fd); } +#else +int +__archive_mktempx(const char *tmpdir, wchar_t *template) +{ + return -1; +} +#endif int __archive_mktemp(const char *tmpdir) diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index 624e2700..828a8543 100644 --- a/libarchive/archive_windows.c +++ b/libarchive/archive_windows.c @@ -235,6 +235,7 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, wchar_t *wpath; HANDLE handle; +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) handle = CreateFileA(path, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); @@ -249,6 +250,20 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); free(wpath); +#else /* !WINAPI_PARTITION_DESKTOP */ + wpath = __la_win_permissive_name(path); + if (wpath == NULL) + return (handle); + CREATEFILE2_EXTENDED_PARAMETERS createExParams; + createExParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); + createExParams.dwFileAttributes = dwFlagsAndAttributes & 0xFFFF; + createExParams.dwFileFlags = dwFlagsAndAttributes & 0xFFF00000; + createExParams.dwSecurityQosFlags = dwFlagsAndAttributes & 0x000F00000; + createExParams.lpSecurityAttributes = lpSecurityAttributes; + createExParams.hTemplateFile = hTemplateFile; + handle = CreateFile2(wpath, dwDesiredAccess, dwShareMode, dwCreationDisposition, &createExParams); + free(wpath); +#endif /* !WINAPI_PARTITION_DESKTOP */ return (handle); } @@ -320,7 +335,7 @@ __la_open(const char *path, int flags, ...) } if (attr & FILE_ATTRIBUTE_DIRECTORY) { HANDLE handle; - +#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) if (ws != NULL) handle = CreateFileW(ws, 0, 0, NULL, OPEN_EXISTING, @@ -333,6 +348,20 @@ __la_open(const char *path, int flags, ...) FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_READONLY, NULL); +#else /* !WINAPI_PARTITION_DESKTOP */ + if (ws != NULL) { + CREATEFILE2_EXTENDED_PARAMETERS createExParams; + createExParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); + createExParams.dwFileAttributes = FILE_ATTRIBUTE_READONLY; + createExParams.dwFileFlags = FILE_FLAG_BACKUP_SEMANTICS; + createExParams.dwSecurityQosFlags = 0; + createExParams.lpSecurityAttributes = NULL; + createExParams.hTemplateFile = NULL; + handle = CreateFile2(ws, 0, 0, OPEN_EXISTING, &createExParams); + } + else + handle = INVALID_HANDLE_VALUE; +#endif /* !WINAPI_PARTITION_DESKTOP */ free(ws); if (handle == INVALID_HANDLE_VALUE) { la_dosmaperr(GetLastError()); diff --git a/libarchive/archive_windows.h b/libarchive/archive_windows.h index 47b7cb8e..9743f310 100644 --- a/libarchive/archive_windows.h +++ b/libarchive/archive_windows.h @@ -106,9 +106,11 @@ #define lseek __la_lseek #define __LA_LSEEK_NEEDED #endif +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #define lstat __la_stat #define open __la_open #define read __la_read +#endif #if !defined(__BORLANDC__) && !defined(__WATCOMC__) #define setmode _setmode #endif @@ -122,8 +124,10 @@ #define umask _umask #endif #endif +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #define waitpid __la_waitpid #define write __la_write +#endif #if !defined(__WATCOMC__) @@ -276,8 +280,10 @@ extern int __la_stat(const char *path, struct stat *st); extern pid_t __la_waitpid(HANDLE child, int *status, int option); extern ssize_t __la_write(int fd, const void *buf, size_t nbytes); +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #define _stat64i32(path, st) __la_stat(path, st) #define _stat64(path, st) __la_stat(path, st) +#endif /* for status returned by la_waitpid */ #define WIFEXITED(sts) ((sts & 0x100) == 0) #define WEXITSTATUS(sts) (sts & 0x0FF) diff --git a/libarchive/filter_fork_windows.c b/libarchive/filter_fork_windows.c index ad271fe6..0414d6f4 100644 --- a/libarchive/filter_fork_windows.c.orig 2020-12-26 02:29:38.000000000 +0100 +++ b/libarchive/filter_fork_windows.c 2021-04-21 17:17:42.651099766 +0200 @@ -31,6 +31,13 @@ #include "filter_fork.h" +#if !WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) +int +__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, HANDLE *out_child) +{ + return ARCHIVE_FAILED; +} +#else /* WINAPI_PARTITION_DESKTOP */ int __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, HANDLE *out_child) @@ -187,6 +194,7 @@ __archive_cmdline_free(acmd); return ARCHIVE_FAILED; } +#endif /* WINAPI_PARTITION_DESKTOP */ void __archive_check_child(int in, int out)