--- /dev/null
+--- a/include/osdep.h
++++ b/include/osdep.h
+@@ -218,6 +218,7 @@
+ #endif /* HAVE_STDDEF_H */
+
+ #if HAVE_PTHREAD_H
++#define _GNU_SOURCE
+ #include <pthread.h>
+ #endif /* HAVE_PTHREAD_H */
+
+--- a/lib/Rbindresvport.c
++++ b/lib/Rbindresvport.c
+@@ -72,11 +72,11 @@ Rbindresvport(s, _sin)
+
+ if (_sin == NULL) {
+ slog(LOG_DEBUG, "%s: fd %d, _sin = %p", function, s, _sin);
+- return bindresvport(s, _sin);
++ return Rbindresvport(s, _sin);
+ }
+
+ usrsockaddrcpy(&sin, TOSS(_sin), sizeof(*_sin));
+- if (bindresvport(s, TOIN(&sin)) != 0) {
++ if (Rbindresvport(s, TOIN(&sin)) != 0) {
+ slog(LOG_DEBUG, "%s: bindresvport(%d, %s) failed: %s",
+ function,
+ s,
+--- a/lib/Rconnect.c
++++ b/lib/Rconnect.c
+@@ -433,7 +433,7 @@ Rconnect(s, _name, namelen)
+ TOIN(&socksfd.local)->sin_port = htons(0);
+
+ /* LINTED pointer casts may be troublesome */
+- bindresvport(s, TOIN(&socksfd.local));
++ Rbindresvport(s, TOIN(&socksfd.local));
+ }
+
+ return Rconnect(s, TOSA(&name), namelen);
+--- a/libscompat.m4
++++ b/libscompat.m4
+@@ -34,6 +34,7 @@ AC_TRY_COMPILE([
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <stdio.h>
++#include <string.h>
+ #include <sys/ioctl.h>
+ #include <net/if.h>
+ #ifndef SIOCGIFHWADDR
+@@ -103,6 +104,7 @@ AC_CHECK_FUNC(getpassphrase,
+
+ AC_MSG_CHECKING([for sched_setaffinity])
+ AC_TRY_COMPILE([
++#define _GNU_SOURCE
+ #include <sched.h>
+ ],
+ [ cpu_set_t set1;