From b29582706bcaf252d7e1c1b73588b338dbfea1e5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 28 Aug 2023 12:18:58 +0200 Subject: [PATCH] fixup! http: support lazy-loading libcurl also on Windows If the `.dll` file could not be loaded, let's print an error message. Signed-off-by: Johannes Schindelin --- compat/lazyload-curl.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/compat/lazyload-curl.c b/compat/lazyload-curl.c index 7fea0dead285b5..d19f99d76619a6 100644 --- a/compat/lazyload-curl.c +++ b/compat/lazyload-curl.c @@ -56,8 +56,22 @@ static void *load_library(const char *name) dll_path[len] = '/'; memcpy(dll_path + len + 1, name, name_size); - if (!access(dll_path, R_OK)) - return (void *)LoadLibraryExA(dll_path, NULL, 0); + if (!access(dll_path, R_OK)) { + void *res = (void *)LoadLibraryExA(dll_path, NULL, 0); + if (!res) { + DWORD err = GetLastError(); + char buf[1024]; + + if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_ARGUMENT_ARRAY | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, LANG_NEUTRAL, + buf, sizeof(buf) - 1, NULL)) + xsnprintf(buf, sizeof(buf), "last error: %ld", err); + error("LoadLibraryExA() failed with: %s", buf); + } + return res; + } } path = *sep ? sep + 1 : NULL;