diff --git a/sysdeps/posix/readdir.c b/sysdeps/posix/readdir.c
index fcd3853..a6ecc0f 100644
--- a/sysdeps/posix/readdir.c
+++ b/sysdeps/posix/readdir.c
@@ -120,3 +120,8 @@ __READDIR (DIR *dirp)
 #ifdef __READDIR_ALIAS
 weak_alias (__readdir, readdir)
 #endif
+
+#undef __READDIR
+#undef __GETDENTS
+#undef DIRENT_TYPE
+#undef __READDIR_ALIAS
diff --git a/sysdeps/posix/readdir_r.c b/sysdeps/posix/readdir_r.c
index 79030ab..2d691e7 100644
--- a/sysdeps/posix/readdir_r.c
+++ b/sysdeps/posix/readdir_r.c
@@ -152,3 +152,8 @@ __READDIR_R (DIR *dirp, DIRENT_TYPE *entry, DIRENT_TYPE **result)
 #ifdef __READDIR_R_ALIAS
 weak_alias (__readdir_r, readdir_r)
 #endif
+
+#undef __READDIR_R
+#undef __GETDENTS
+#undef DIRENT_TYPE
+#undef __READDIR_R_ALIAS
diff --git a/sysdeps/unix/sysv/linux/arm/readdir64.c b/sysdeps/unix/sysv/linux/arm/readdir64.c
deleted file mode 100644
index 2ea26dd..0000000
--- a/sysdeps/unix/sysv/linux/arm/readdir64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/sysdeps/unix/sysv/linux/arm/readdir64_r.c b/sysdeps/unix/sysv/linux/arm/readdir64_r.c
deleted file mode 100644
index 9f54f89..0000000
--- a/sysdeps/unix/sysv/linux/arm/readdir64_r.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/readdir64.c b/sysdeps/unix/sysv/linux/m68k/readdir64.c
deleted file mode 100644
index 2ea26dd..0000000
--- a/sysdeps/unix/sysv/linux/m68k/readdir64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/readdir64_r.c b/sysdeps/unix/sysv/linux/m68k/readdir64_r.c
deleted file mode 100644
index 9f54f89..0000000
--- a/sysdeps/unix/sysv/linux/m68k/readdir64_r.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/readdir64.c b/sysdeps/unix/sysv/linux/powerpc/readdir64.c
deleted file mode 100644
index 2ea26dd..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/readdir64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c b/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c
deleted file mode 100644
index 9f54f89..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/sysdeps/unix/sysv/linux/i386/readdir64_r.c b/sysdeps/unix/sysv/linux/readdir.c
similarity index 52%
rename from sysdeps/unix/sysv/linux/i386/readdir64_r.c
rename to sysdeps/unix/sysv/linux/readdir.c
index 31862a0..b99bc96 100644
--- a/sysdeps/unix/sysv/linux/i386/readdir64_r.c
+++ b/sysdeps/unix/sysv/linux/readdir.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
+/* Read a directory.  Linux no-LFS version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -15,29 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __READDIR_R __readdir64_r
-#define __GETDENTS __getdents64
-#define DIRENT_TYPE struct dirent64
+#include <dirent.h>
 
-#include <sysdeps/posix/readdir_r.c>
-
-#undef __READDIR_R
-#undef __GETDENTS
-#undef DIRENT_TYPE
-
-#include <shlib-compat.h>
-
-versioned_symbol (libc, __readdir64_r, readdir64_r, GLIBC_2_2);
-
-#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
-
-#include <olddirent.h>
-
-#define __READDIR_R attribute_compat_text_section __old_readdir64_r
-#define __GETDENTS __old_getdents64
-#define DIRENT_TYPE struct __old_dirent64
-
-#include <sysdeps/posix/readdir_r.c>
-
-compat_symbol (libc, __old_readdir64_r, readdir64_r, GLIBC_2_1);
+#if !_DIRENT_MATCHES_DIRENT64
+# include <sysdeps/posix/readdir.c>
 #endif
diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c
index 6d154fe..054e4ff 100644
--- a/sysdeps/unix/sysv/linux/readdir64.c
+++ b/sysdeps/unix/sysv/linux/readdir64.c
@@ -1,8 +1,55 @@
-#define __READDIR __readdir64
-#define __GETDENTS __getdents64
+/* Read a directory.  Linux LFS version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* When _DIRENT_MATCHES_DIRENT64 is defined we can alias 'readdir64' to
+   'readdir'.  However the function signatures are not equal due
+   different return types, so we need to suppress {__}readdir so weak
+   and strong alias do not throw conflicting types errors.  */
+#define readdir __no_readdir_decl
+#define __readdir __no___readdir_decl
+#include <dirent.h>
+
+#define __READDIR   __readdir64
+#define __GETDENTS  __getdents64
 #define DIRENT_TYPE struct dirent64
 
 #include <sysdeps/posix/readdir.c>
 
+#undef __readdir
+#undef readdir
+
 libc_hidden_def (__readdir64)
+#if _DIRENT_MATCHES_DIRENT64
+strong_alias (__readdir64, __readdir)
 weak_alias (__readdir64, readdir64)
+weak_alias (__readdir64, readdir)
+#else
+/* The compat code expects the 'struct direct' with d_ino being a __ino_t
+   instead of __ino64_t.  */
+# include <shlib-compat.h>
+versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2);
+# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+#  include <olddirent.h>
+#  define __READDIR   attribute_compat_text_section __old_readdir64
+#  define __GETDENTS  __old_getdents64
+#  define DIRENT_TYPE struct __old_dirent64
+#  include <sysdeps/posix/readdir.c>
+libc_hidden_def (__old_readdir64)
+compat_symbol (libc, __old_readdir64, readdir64, GLIBC_2_1);
+# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)  */
+#endif /* _DIRENT_MATCHES_DIRENT64  */
diff --git a/sysdeps/unix/sysv/linux/readdir64_r.c b/sysdeps/unix/sysv/linux/readdir64_r.c
index 3dfbf4f..22b23d5 100644
--- a/sysdeps/unix/sysv/linux/readdir64_r.c
+++ b/sysdeps/unix/sysv/linux/readdir64_r.c
@@ -1,7 +1,53 @@
+/* Read a directory in reentrant mode.  Linux LFS version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* When _DIRENT_MATCHES_DIRENT64 is defined we can alias 'readdir64' to
+   'readdir'.  However the function signatures are not equal due
+   different return types, so we need to suppress {__}readdir so weak
+   and strong alias do not throw conflicting types errors.  */
+#define readdir_r   __no_readdir_r_decl
+#define __readdir_r __no___readdir_r_decl
+#include <dirent.h>
+
 #define __READDIR_R __readdir64_r
-#define __GETDENTS __getdents64
+#define __GETDENTS  __getdents64
 #define DIRENT_TYPE struct dirent64
 
 #include <sysdeps/posix/readdir_r.c>
 
+#undef __readdir_r
+#undef readdir_r
+
+#if _DIRENT_MATCHES_DIRENT64
+strong_alias (__readdir64_r, __readdir_r)
+weak_alias (__readdir64_r, readdir_r)
 weak_alias (__readdir64_r, readdir64_r)
+#else
+/* The compat code expects the 'struct direct' with d_ino being a __ino_t
+   instead of __ino64_t.  */
+# include <shlib-compat.h>
+versioned_symbol (libc, __readdir64_r, readdir64_r, GLIBC_2_2);
+# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
+#  include <olddirent.h>
+#  define __READDIR_R attribute_compat_text_section __old_readdir64_r
+#  define __GETDENTS  __old_getdents64
+#  define DIRENT_TYPE struct __old_dirent64
+#  include <sysdeps/posix/readdir_r.c>
+compat_symbol (libc, __old_readdir64_r, readdir64_r, GLIBC_2_1);
+# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)  */
+#endif /* _DIRENT_MATCHES_DIRENT64  */
diff --git a/sysdeps/unix/sysv/linux/i386/readdir64.c b/sysdeps/unix/sysv/linux/readdir_r.c
similarity index 51%
rename from sysdeps/unix/sysv/linux/i386/readdir64.c
rename to sysdeps/unix/sysv/linux/readdir_r.c
index 42b7302..7ca9e8e 100644
--- a/sysdeps/unix/sysv/linux/i386/readdir64.c
+++ b/sysdeps/unix/sysv/linux/readdir_r.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
+/* Read a directory in reentrant mode.  Linux no-LFS version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -15,32 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#define __READDIR __readdir64
-#define __GETDENTS __getdents64
-#define DIRENT_TYPE struct dirent64
+#include <dirent.h>
 
-#include <sysdeps/posix/readdir.c>
-
-#include <shlib-compat.h>
-
-#undef __READDIR
-#undef __GETDENTS
-#undef DIRENT_TYPE
-
-libc_hidden_def (__readdir64)
-versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2);
-
-#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
-
-#include <olddirent.h>
-
-#define __READDIR attribute_compat_text_section __old_readdir64
-#define __GETDENTS __old_getdents64
-#define DIRENT_TYPE struct __old_dirent64
-
-#include <sysdeps/posix/readdir.c>
-
-libc_hidden_def (__old_readdir64)
-
-compat_symbol (libc, __old_readdir64, readdir64, GLIBC_2_1);
+#if !_DIRENT_MATCHES_DIRENT64
+# include <sysdeps/posix/readdir_r.c>
 #endif
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c b/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c
deleted file mode 100644
index 2ea26dd..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c b/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c
deleted file mode 100644
index 9f54f89..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c b/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c
deleted file mode 100644
index 2ea26dd..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c b/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c
deleted file mode 100644
index 9f54f89..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/readdir64_r.c>
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir.c
deleted file mode 100644
index 0d57988..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/readdir.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#define readdir64 __no_readdir64_decl
-#define __readdir64 __no___readdir64_decl
-#include <sysdeps/posix/readdir.c>
-#undef __readdir64
-strong_alias (__readdir, __readdir64)
-strong_alias (__readdir, __GI___readdir64)
-#undef readdir64
-weak_alias (__readdir, readdir64)
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c
deleted file mode 100644
index 9796431..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* readdir64 is in readdir.c */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c
deleted file mode 100644
index b8fe9a3..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c
+++ /dev/null
@@ -1 +0,0 @@
-/* readdir64_r is in readdir_r.c */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c
deleted file mode 100644
index 290f2c8..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c
+++ /dev/null
@@ -1,4 +0,0 @@
-#define readdir64_r __no_readdir64_r_decl
-#include <sysdeps/posix/readdir_r.c>
-#undef readdir64_r
-weak_alias (__readdir_r, readdir64_r)
