diff --git a/lib/isc/win32/ltdl.h b/lib/isc/win32/ltdl.h new file mode 100644 index 0000000000..16beb862ea --- /dev/null +++ b/lib/isc/win32/ltdl.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#pragma once + +#include + +#define lt_dlhandle HMODULE +#define lt_dlinit() ISC_R_SUCCESS +#define lt_dlopen(f) LoadLibraryW(f) +#define lt_dlsym(h, s) GetProcAddress(h, s) +#define lt_dlclose(h) FreeLibrary(h) + +_Thread_local LPSTR __dlerror_message[1024] = { 0 }; + +static const char * +lt_dlerror(void) { + DWORD errorMessageID = GetLastError(); + if (errorMessageID == 0) { + return (NULL); + } + + LPSTR messageBuffer = NULL; + size_t size = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&messageBuffer, 0, NULL); + + strlcpy(__dlerror_message, messageBuffer, sizeof(__dlerror_message)); + + LocalFree(messageBuffer); + + return ((const char *)__dlerror_message); +} diff --git a/util/copyrights b/util/copyrights index ee53272280..119596c90b 100644 --- a/util/copyrights +++ b/util/copyrights @@ -2031,6 +2031,7 @@ ./lib/isc/win32/libisc.vcxproj.filters.in X 2013,2014,2015,2016,2018,2019,2020 ./lib/isc/win32/libisc.vcxproj.in X 2013,2014,2015,2016,2017,2018,2019,2020 ./lib/isc/win32/libisc.vcxproj.user X 2013,2018,2019,2020 +./lib/isc/win32/ltdl.h C 2020 ./lib/isc/win32/meminfo.c C 2015,2016,2018,2019,2020 ./lib/isc/win32/net.c C 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2011,2012,2013,2014,2015,2016,2018,2019,2020 ./lib/isc/win32/netdb.h C 2000,2001,2004,2006,2007,2009,2013,2016,2018,2019,2020