1From db3a551e932481d4ccdd315fb05cd24910807136 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 7 Jul 2017 15:27:50 -0700
4Subject: [PATCH] chromium: musl: Define res_ninit and res_nclose for non-glibc
5 platforms
6
7Signed-off-by: Khem Raj <raj.khem@gmail.com>
8Upstream-Status: Pending
9---
10 chromium/net/dns/dns_config_service_posix.cc |  4 +++
11 chromium/net/dns/dns_reloader.cc             |  4 +++
12 chromium/net/dns/resolv_compat.h             | 29 ++++++++++++++++++++
13 3 files changed, 37 insertions(+)
14 create mode 100644 chromium/net/dns/resolv_compat.h
15
16diff --git a/chromium/net/dns/dns_config_service_posix.cc b/chromium/net/dns/dns_config_service_posix.cc
17index 5a4aead0acf..3427923836b 100644
18--- a/chromium/net/dns/dns_config_service_posix.cc
19+++ b/chromium/net/dns/dns_config_service_posix.cc
20@@ -30,6 +30,10 @@
21 #include "net/dns/public/dns_protocol.h"
22 #include "net/dns/serial_worker.h"
23
24+#if defined(OS_LINUX) && !defined(__GLIBC__)
25+#include "net/dns/resolv_compat.h"
26+#endif
27+
28 #if defined(OS_MAC)
29 #include "net/dns/dns_config_watcher_mac.h"
30 #endif
31diff --git a/chromium/net/dns/dns_reloader.cc b/chromium/net/dns/dns_reloader.cc
32index 0672e711afb..300f77e3b38 100644
33--- a/chromium/net/dns/dns_reloader.cc
34+++ b/chromium/net/dns/dns_reloader.cc
35@@ -9,6 +9,10 @@
36
37 #include <resolv.h>
38
39+#if defined(OS_LINUX) && !defined(__GLIBC__)
40+#include "net/dns/resolv_compat.h"
41+#endif
42+
43 #include "base/lazy_instance.h"
44 #include "base/macros.h"
45 #include "base/notreached.h"
46diff --git a/chromium/net/dns/resolv_compat.h b/chromium/net/dns/resolv_compat.h
47new file mode 100644
48index 00000000000..4f0e852a19d
49--- /dev/null
50+++ b/chromium/net/dns/resolv_compat.h
51@@ -0,0 +1,29 @@
52+#if !defined(__GLIBC__)
53+/***************************************************************************
54+ * resolv_compat.h
55+ *
56+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
57+ * Note: res_init() is actually deprecated according to
58+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
59+ **************************************************************************/
60+#include <string.h>
61+
62+static inline int res_ninit(res_state statp)
63+{
64+	int rc = res_init();
65+	if (statp != &_res) {
66+		memcpy(statp, &_res, sizeof(*statp));
67+	}
68+	return rc;
69+}
70+
71+static inline int res_nclose(res_state statp)
72+{
73+	if (!statp)
74+		return -1;
75+	if (statp != &_res) {
76+		memset(statp, 0, sizeof(*statp));
77+	}
78+	return 0;
79+}
80+#endif
81