use __h_errno_location for h_errno
authorRich Felker <dalias@aerifal.cx>
Sun, 13 May 2012 03:45:07 +0000 (23:45 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 13 May 2012 03:45:07 +0000 (23:45 -0400)
we do not bother making h_errno thread-local since the only interfaces
that use it are inherently non-thread-safe. but still use the
potentially-thread-local ABI to access it just to avoid lock-in.

include/netdb.h
src/network/h_errno.c
src/network/res_query.c

index a480d82..33b7a0a 100644 (file)
@@ -128,7 +128,11 @@ struct hostent *gethostbyaddr (const void *, socklen_t, int);
 int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
 int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
 int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
-extern int h_errno;
+#ifdef __GNUC__
+__attribute__((const))
+#endif
+int *__h_errno_location(void);
+#define h_errno (*__h_errno_location())
 #define EAI_NODATA     -5
 #define EAI_ADDRFAMILY -9
 #define EAI_INPROGRESS -100
index 73ead04..5560234 100644 (file)
@@ -1 +1,9 @@
+#include <netdb.h>
+
+#undef h_errno;
 int h_errno;
+
+int *__h_errno_location(void)
+{
+       return &h_errno;
+}
index 4200999..c3ad109 100644 (file)
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
 #include <netdb.h>
 #include "__dns.h"
 #include "libc.h"