Skip to content

Commit f1e3572

Browse files
committed
http: support lazy-loading libcurl also on Windows
This implements the Windows-specific support code, because everything is slightly different on Windows, even loading shared libraries. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2d1ad10 commit f1e3572

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,11 @@ else
16121612
LAZY_LOAD_LIBCURL_OBJ = compat/lazy-load-curl.o
16131613
OBJECTS += $(LAZY_LOAD_LIBCURL_OBJ)
16141614
CURL_CFLAGS = -DCURL_STATICLIB
1615+
ifneq ($(uname_S),MINGW)
1616+
ifneq ($(uname_S),Windows)
16151617
CURL_LIBCURL = -ldl
1618+
endif
1619+
endif
16161620
else
16171621
ifndef CURL_LDFLAGS
16181622
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)

compat/lazy-load-curl.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "../git-compat-util.h"
22
#include "../git-curl-compat.h"
3+
#ifndef WIN32
34
#include <dlfcn.h>
5+
#endif
46

57
typedef void (*func_t)(void);
68

9+
#ifndef WIN32
710
#ifdef __APPLE__
811
#define LIBCURL_FILE_NAME(base) base ".4.dylib"
912
#else
@@ -28,6 +31,39 @@ static func_t load_function(void *handle, const char *name)
2831
*(void **)&f = dlsym(handle, name);
2932
return f;
3033
}
34+
#else
35+
#define LIBCURL_FILE_NAME(base) base "-4.dll"
36+
37+
static void *load_library(const char *name)
38+
{
39+
size_t name_size = strlen(name) + 1;
40+
const char *path = getenv("PATH");
41+
char dll_path[MAX_PATH];
42+
43+
while (path && *path) {
44+
const char *sep = strchrnul(path, ';');
45+
size_t len = sep - path;
46+
47+
if (len && len + name_size < sizeof(dll_path)) {
48+
memcpy(dll_path, path, len);
49+
dll_path[len] = '/';
50+
memcpy(dll_path + len + 1, name, name_size);
51+
52+
if (!access(dll_path, R_OK))
53+
return (void *)LoadLibraryExA(dll_path, NULL, 0);
54+
}
55+
56+
path = *sep ? sep + 1 : NULL;
57+
}
58+
59+
return NULL;
60+
}
61+
62+
static func_t load_function(void *handle, const char *name)
63+
{
64+
return (func_t)GetProcAddress((HANDLE)handle, name);
65+
}
66+
#endif
3167

3268
typedef char *(*curl_easy_escape_type)(CURL *handle, const char *string, int length);
3369
static curl_easy_escape_type curl_easy_escape_func;

0 commit comments

Comments
 (0)