summaryrefslogtreecommitdiff
path: root/libarchive
diff options
context:
space:
mode:
authorDustin Howett <duhowett@microsoft.com>2021-10-13 14:36:05 -0700
committerDustin L. Howett <dustin@howett.net>2021-11-20 15:01:06 -0600
commit96ac7da33547fd61d63bc7d97f390108702dd44f (patch)
treec2e9ffe65d49bbe493116c004b32deb4ac90bcb5 /libarchive
parentede459d2ebb879f5eedb6f7abea203be0b334230 (diff)
downloadlibarchive-96ac7da33547fd61d63bc7d97f390108702dd44f.tar.gz
Remove dependency on user32
Diffstat (limited to 'libarchive')
-rw-r--r--libarchive/filter_fork_windows.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/libarchive/filter_fork_windows.c b/libarchive/filter_fork_windows.c
index 8d11179f..0b963975 100644
--- a/libarchive/filter_fork_windows.c
+++ b/libarchive/filter_fork_windows.c
@@ -31,6 +31,43 @@
#include "filter_fork.h"
+/* There are some editions of Windows ("nano server," for example) that
+ * do not host user32.dll. If we want to keep running on those editions,
+ * we need to delay-load WaitForInputIdle. */
+static void *
+la_GetFunctionUser32(const char *name)
+{
+ static HINSTANCE lib;
+ static int set;
+ if (!set) {
+ set = 1;
+ lib = LoadLibrary(TEXT("user32.dll"));
+ }
+ if (lib == NULL) {
+ return NULL;
+ }
+ return (void *)GetProcAddress(lib, name);
+}
+
+static int
+la_WaitForInputIdle(HANDLE hProcess, DWORD dwMilliseconds)
+{
+ static DWORD (WINAPI *f)(HANDLE, DWORD);
+ static int set;
+
+ if (!set) {
+ set = 1;
+ f = la_GetFunctionUser32("WaitForInputIdle");
+ }
+
+ if (!f) {
+ /* An inability to wait for input idle is
+ * not _good_, but it is not catastrophic. */
+ return WAIT_FAILED;
+ }
+ return (*f)(hProcess, dwMilliseconds);
+}
+
int
__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
HANDLE *out_child)
@@ -149,7 +186,7 @@ __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
if (CreateProcessA(fullpath.s, cmdline.s, NULL, NULL, TRUE, 0,
NULL, NULL, &staInfo, &childInfo) == 0)
goto fail;
- WaitForInputIdle(childInfo.hProcess, INFINITE);
+ la_WaitForInputIdle(childInfo.hProcess, INFINITE);
CloseHandle(childInfo.hProcess);
CloseHandle(childInfo.hThread);