Skip to content

Commit

Permalink
Merge remote branch 'github/win_lib'
Browse files Browse the repository at this point in the history
  • Loading branch information
nmathewson committed Sep 27, 2010
2 parents b395392 + d49b5e3 commit a78ac0f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion evdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -3509,7 +3509,8 @@ load_nameservers_with_getnetworkparams(struct evdns_base *base)
GetNetworkParams_fn_t fn;

ASSERT_LOCKED(base);
if (!(handle = LoadLibrary(TEXT("iphlpapi.dll")))) {
if (!(handle = evutil_load_windows_system_library(
TEXT("iphlpapi.dll")))) {
log(EVDNS_LOG_WARN, "Could not open iphlpapi.dll");
status = -1;
goto done;
Expand Down
17 changes: 17 additions & 0 deletions evutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <io.h>
#include <tchar.h>
#endif

#include <sys/types.h>
Expand Down Expand Up @@ -2060,3 +2061,19 @@ evutil_hex_char_to_int(char c)
}
return -1;
}

#ifdef WIN32
HANDLE
evutil_load_windows_system_library(const TCHAR *library_name)
{
TCHAR path[MAX_PATH];
unsigned n;
n = GetSystemDirectory(path, MAX_PATH);
if (n == 0 || n + _tcslen(library_name) + 2 >= MAX_PATH)
return 0;
_tcscat(path, TEXT("\\"));
_tcscat(path, library_name);
return LoadLibrary(path);
}
#endif

19 changes: 19 additions & 0 deletions test/regress_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,22 @@ test_evutil_getaddrinfo(void *arg)
evutil_freeaddrinfo(ai);
}

#ifdef WIN32
static void
test_evutil_loadsyslib(void *arg)
{
HANDLE h=NULL;

h = evutil_load_windows_system_library(TEXT("kernel32.dll"));
tt_assert(h);

end:
if (h)
CloseHandle(h);

}
#endif

struct testcase_t util_testcases[] = {
{ "ipv4_parse", regress_ipv4_parse, 0, NULL, NULL },
{ "ipv6_parse", regress_ipv6_parse, 0, NULL, NULL },
Expand All @@ -1052,6 +1068,9 @@ struct testcase_t util_testcases[] = {
{ "integers", test_evutil_integers, 0, NULL, NULL },
{ "rand", test_evutil_rand, TT_FORK, NULL, NULL },
{ "getaddrinfo", test_evutil_getaddrinfo, TT_FORK, NULL, NULL },
#ifdef WIN32
{ "loadsyslib", test_evutil_loadsyslib, TT_FORK, NULL, NULL },
#endif
END_OF_TESTCASES,
};

4 changes: 4 additions & 0 deletions util-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ long evutil_tv_to_msec(const struct timeval *tv);

int evutil_hex_char_to_int(char c);

#ifdef WIN32
HANDLE evutil_load_windows_system_library(const TCHAR *library_name);
#endif

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit a78ac0f

Please sign in to comment.