blob: c09bc12520aa31293983ac01bf1cf504edf6477e [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001From f93b680ec1a816ffe90d5f1bce609f8bf68a456e Mon Sep 17 00:00:00 2001
Andrew Geisslere34f8962021-04-15 15:53:51 -05002From: Trevor Gamblin <trevor.gamblin@windriver.com>
3Date: Wed, 14 Apr 2021 10:24:52 -0400
4Subject: [PATCH] Add resolv_compat.h for musl builds
5
6musl doesn't implement res_ninit, so it needs to be defined
7independently for musl builds. This patch is based on the one at
8https://gitweb.gentoo.org/proj/musl.git/tree/dev-qt/qtwebengine/files/qtwebengine-5.7.0-musl-resolver.patch?id=7f4100326793d55d45d0f5bb6178827ce6173513
9
10Upstream-Status: Pending
11
12Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com>
Andrew Geissler595f6302022-01-24 19:11:47 +000013
Andrew Geisslere34f8962021-04-15 15:53:51 -050014---
15 open-vm-tools/lib/nicInfo/nicInfoPosix.c | 4 +++
16 open-vm-tools/lib/nicInfo/resolv_compat.h | 30 +++++++++++++++++++++++
17 2 files changed, 34 insertions(+)
18 create mode 100644 open-vm-tools/lib/nicInfo/resolv_compat.h
19
20diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
Andrew Geissler595f6302022-01-24 19:11:47 +000021index c56b73cf..8ae3b2f7 100644
Andrew Geisslere34f8962021-04-15 15:53:51 -050022--- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c
23+++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
24@@ -70,6 +70,10 @@
25 # include <net/if.h>
26 #endif
27
28+#if !defined(__GLIBC__)
29+#include "resolv_compat.h"
30+#endif
31+
32 /*
33 * resolver(3) and IPv6:
34 *
35diff --git a/open-vm-tools/lib/nicInfo/resolv_compat.h b/open-vm-tools/lib/nicInfo/resolv_compat.h
36new file mode 100644
37index 00000000..d768464b
38--- /dev/null
39+++ b/open-vm-tools/lib/nicInfo/resolv_compat.h
40@@ -0,0 +1,30 @@
41+#if !defined(__GLIBC__)
42+/***************************************************************************
43+ * resolv_compat.h
44+ *
45+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
46+ * Note: res_init() is actually deprecated according to
47+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
48+ **************************************************************************/
49+#include <string.h>
50+
51+static inline int res_ninit(res_state statp)
52+{
53+ int rc = res_init();
54+ if (statp != &_res) {
55+ memcpy(statp, &_res, sizeof(*statp));
56+ }
57+ return rc;
58+}
59+
60+static inline int res_nclose(res_state statp)
61+{
62+ if (!statp)
63+ return -1;
64+ if (statp != &_res) {
65+ memset(statp, 0, sizeof(*statp));
66+ }
67+ return 0;
68+}
69+#endif
70+