Another bulky set of minor changes.
Note addition of gethostbyaddr() and improved repr() for sockets,
renaming of md5.md5() to md5.new(), and fixing of leaks in threads.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index c2678eb..3e3f9cc 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -97,23 +97,22 @@
 #define MAXPATHLEN 1024
 #endif /* MAXPATHLEN */
 
-/* unistd.h defines _POSIX_VERSION on POSIX.1 systems.  */
-#if defined(DIRENT) || defined(_POSIX_VERSION)
+#ifdef HAVE_DIRENT_H
 #include <dirent.h>
-#define NLENGTH(dirent) (strlen((dirent)->d_name))
-#else /* not (DIRENT or _POSIX_VERSION) */
+#define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
 #define dirent direct
-#define NLENGTH(dirent) ((dirent)->d_namlen)
-#ifdef SYSNDIR
+#define NAMLEN(dirent) (dirent)->d_namlen
+#ifdef HAVE_SYS_NDIR_H
 #include <sys/ndir.h>
-#endif /* SYSNDIR */
-#ifdef SYSDIR
+#endif
+#ifdef HAVE_SYS_DIR_H
 #include <sys/dir.h>
-#endif /* SYSDIR */
-#ifdef NDIR
+#endif
+#ifdef HAVE_NDIR_H
 #include <ndir.h>
-#endif /* NDIR */
-#endif /* not (DIRENT or _POSIX_VERSION) */
+#endif
+#endif
 
 #ifdef NT
 #include <direct.h>
@@ -406,7 +405,7 @@
 		return NULL;
 	}
 	while ((ep = readdir(dirp)) != NULL) {
-		v = newstringobject(ep->d_name);
+		v = newsizedstringobject(ep->d_name, NAMLEN(ep));
 		if (v == NULL) {
 			DECREF(d);
 			d = NULL;