1From 148aadcc1b61da6f6b9ee4bcd35c38b7fbaeb8a8 Mon Sep 17 00:00:00 2001
2From: 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>
13---
14 open-vm-tools/lib/nicInfo/nicInfoPosix.c  |  4 +++
15 open-vm-tools/lib/nicInfo/resolv_compat.h | 30 +++++++++++++++++++++++
16 2 files changed, 34 insertions(+)
17 create mode 100644 open-vm-tools/lib/nicInfo/resolv_compat.h
18
19diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
20index 6f20547b2..f5064a9c0 100644
21--- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c
22+++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c
23@@ -70,6 +70,10 @@
24 #   include <net/if.h>
25 #endif
26
27+#if !defined(__GLIBC__)
28+#include "resolv_compat.h"
29+#endif
30+
31 /*
32  * resolver(3) and IPv6:
33  *
34diff --git a/open-vm-tools/lib/nicInfo/resolv_compat.h b/open-vm-tools/lib/nicInfo/resolv_compat.h
35new file mode 100644
36index 000000000..d768464b9
37--- /dev/null
38+++ b/open-vm-tools/lib/nicInfo/resolv_compat.h
39@@ -0,0 +1,30 @@
40+#if !defined(__GLIBC__)
41+/***************************************************************************
42+ * resolv_compat.h
43+ *
44+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
45+ * Note: res_init() is actually deprecated according to
46+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
47+ **************************************************************************/
48+#include <string.h>
49+
50+static inline int res_ninit(res_state statp)
51+{
52+	int rc = res_init();
53+	if (statp != &_res) {
54+		memcpy(statp, &_res, sizeof(*statp));
55+	}
56+	return rc;
57+}
58+
59+static inline int res_nclose(res_state statp)
60+{
61+	if (!statp)
62+		return -1;
63+	if (statp != &_res) {
64+		memset(statp, 0, sizeof(*statp));
65+	}
66+	return 0;
67+}
68+#endif
69+
70--
712.25.1
72
73