summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/resolv.h14
-rw-r--r--libc/inet/resolv.c15
2 files changed, 19 insertions, 10 deletions
diff --git a/include/resolv.h b/include/resolv.h
index 940f1ae0a..1f0aea0be 100644
--- a/include/resolv.h
+++ b/include/resolv.h
@@ -230,6 +230,12 @@ typedef struct __res_state *res_state;
#define RES_PRF_INIT 0x00004000
/* 0x00008000 */
+/* Things involving an internal (static) resolver context. */
+__BEGIN_DECLS
+extern struct __res_state *__res_state(void) __attribute__ ((__const__));
+__END_DECLS
+#define _res (*__res_state())
+
#ifndef __BIND_NOSTATIC
#define fp_nquery __fp_nquery
@@ -383,11 +389,9 @@ __END_DECLS
#endif /* _RESOLV_H_ */
-/* Internal (static) resolver context. */
-#ifdef __PTHREADS_NATIVE__
-#include <tls.h>
+#if defined(__PTHREADS_NATIVE__) && defined(IS_IN_libpthread)
+# include <tls.h>
+# undef _res
# define _res (*__resp)
extern __thread struct __res_state *__resp attribute_tls_model_ie;
-#else
-extern struct __res_state _res;
#endif
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 5e82c95d6..bb188b959 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1096,17 +1096,22 @@ struct hostent *gethostbyname2(const char *name, int family)
#ifdef L_res_init
+#undef _res
+struct __res_state _res;
+
+struct __res_state * weak_const_function __res_state (void)
+{
+ return &_res;
+}
+
#ifdef __PTHREADS_NATIVE__
#include <tls.h>
-struct __res_state _res_thread;
-__thread struct __res_state *__resp = &_res_thread;
-#else
-struct __res_state _res;
+__thread struct __res_state *__resp = &_res;
#endif
int res_init(void)
{
- struct __res_state *rp = &(_res);
+ struct __res_state *rp = __res_state();
__close_nameservers();
__open_nameservers();