From: Ondřej Surý Date: Thu, 27 May 2021 10:34:06 +0000 (+0200) Subject: Add uv_os_getenv() and uv_os_setenv() compatibility shims X-Git-Tag: v9.17.14~13^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7477d1b2edb6c63c6818bbae60c043b0158a05cf;p=thirdparty%2Fbind9.git Add uv_os_getenv() and uv_os_setenv() compatibility shims The uv_os_getenv() and uv_os_setenv() functions were introduced in the libuv >= 1.12.0. Add simple compatibility shims for older versions. --- diff --git a/config.h.win32 b/config.h.win32 index abb3ba29577..6ebb165b5c5 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -384,6 +384,12 @@ typedef __int64 off_t; /* Define to 1 if you have the `uv_handle_set_data' function. */ #define HAVE_UV_HANDLE_SET_DATA 1 +/* Define to 1 if you have the `uv_os_getenv' function. */ +#define HAVE_UV_OS_GETENV 1 + +/* Define to 1 if you have the `uv_os_setenv' function. */ +#define HAVE_UV_OS_SETENV 1 + /* Define to 1 if you have the `uv_req_get_data' function. */ #define HAVE_UV_REQ_GET_DATA 1 diff --git a/configure.ac b/configure.ac index dc458b41725..9b947ff4d86 100644 --- a/configure.ac +++ b/configure.ac @@ -603,6 +603,7 @@ LIBS="$LIBS $LIBUV_LIBS" AC_CHECK_FUNCS([uv_handle_get_data uv_handle_set_data]) AC_CHECK_FUNCS([uv_req_get_data uv_req_set_data]) AC_CHECK_FUNCS([uv_udp_connect uv_translate_sys_error uv_sleep]) +AC_CHECK_FUNCS([uv_os_getenv uv_os_setenv]) AX_RESTORE_FLAGS([libuv]) # libnghttp2 diff --git a/lib/isc/netmgr/uv-compat.h b/lib/isc/netmgr/uv-compat.h index 9d9b437294f..2020689c719 100644 --- a/lib/isc/netmgr/uv-compat.h +++ b/lib/isc/netmgr/uv-compat.h @@ -55,6 +55,36 @@ uv_req_set_data(uv_req_t *req, void *data) { #define isc_uv_udp_connect uv_udp_connect #else +#ifndef HAVE_UV_OS_GETENV +#include +#include + +static inline int +uv_os_getenv(const char *name, char *buffer, size_t *size) { + size_t len; + char *buf = getenv(name); + + if (buf == NULL) { + return (UV_ENOENT); + } + + len = strlen(buf) + 1; + if (len > *size) { + *size = len; + return (UV_ENOBUFS); + } + + *size = len; + memmove(buffer, buf, len); + + return (0); +} +#endif /* HAVE_UV_OS_GETENV */ + +#ifndef HAVE_UV_OS_SETENV +#define uv_os_setenv(name, value) setenv(name, value, 0) +#endif /* HAVE_UV_OS_SETENV */ + int isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr); /*%<