generic/wordsize-32: don't declare getdents() if not needed
Commit Message
Modern 32-bit arches has off_t and ino_t types both 64-bit length. It means that
struct dirent is the same as struct dirent64. So we can avoid useless conversion
from 64- to 32-bit dirent layout, and simply alias __getdents64() to __getdents().
The same is true if __USE_FILE_OFFSET64 option is enabled.
Tested with aarch64/ilp32.
2016-09-19: Yury Norov <ynorov@caviumnetworks.com>
* sysdeps/unix/sysv/linux/bits/dirent.h: enable _DIRENT_MATCHES_DIRENT64
if __USE_FILE_OFFSET64 is enabled.
* sysdeps/unix/sysv/linux/generic/getdents64.c: alias __getdents64() to
__getdents() also if _DIRENT_MATCHES_DIRENT64 is enabled.
* sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c: don't declare
__getdents() if _DIRENT_MATCHES_DIRENT64 is enabled.
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
sysdeps/unix/sysv/linux/bits/dirent.h | 3 ++-
sysdeps/unix/sysv/linux/generic/getdents64.c | 3 ++-
sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c | 2 ++
3 files changed, 6 insertions(+), 2 deletions(-)
Comments
On Mon, Sep 19, 2016 at 07:56:44PM +0300, Yury Norov wrote:
>
> Modern 32-bit arches has off_t and ino_t types both 64-bit length. It means that
> struct dirent is the same as struct dirent64. So we can avoid useless conversion
> from 64- to 32-bit dirent layout, and simply alias __getdents64() to __getdents().
> The same is true if __USE_FILE_OFFSET64 option is enabled.
>
> Tested with aarch64/ilp32.
>
> 2016-09-19: Yury Norov <ynorov@caviumnetworks.com>
>
> * sysdeps/unix/sysv/linux/bits/dirent.h: enable _DIRENT_MATCHES_DIRENT64
> if __USE_FILE_OFFSET64 is enabled.
> * sysdeps/unix/sysv/linux/generic/getdents64.c: alias __getdents64() to
> __getdents() also if _DIRENT_MATCHES_DIRENT64 is enabled.
> * sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c: don't declare
> __getdents() if _DIRENT_MATCHES_DIRENT64 is enabled.
>
> Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
Ping?
@@ -51,7 +51,8 @@ struct dirent64
#define _DIRENT_HAVE_D_OFF
#define _DIRENT_HAVE_D_TYPE
-#if defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T
+#if (defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T) \
+ || defined __USE_FILE_OFFSET64
/* Inform libc code that these two types are effectively identical. */
# define _DIRENT_MATCHES_DIRENT64 1
#endif
@@ -16,6 +16,7 @@
License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
+#include <dirent.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
@@ -32,6 +33,6 @@ __getdents64 (int fd, char *buf, size_t nbytes)
return INLINE_SYSCALL (getdents64, 3, fd, buf, nbytes);
}
-#if __WORDSIZE == 64
+#if (__WORDSIZE == 64) || defined (_DIRENT_MATCHES_DIRENT64)
strong_alias (__getdents64, __getdents)
#endif
@@ -30,6 +30,7 @@
#include <sysdep.h>
#include <sys/syscall.h>
+#ifndef _DIRENT_MATCHES_DIRENT64
/* Pack the dirent64 struct down into 32-bit offset/inode fields, and
ensure that no overflow occurs. */
ssize_t
@@ -113,3 +114,4 @@ __getdents (int fd, char *buf, size_t nbytes)
return outp->b - buf;
}
+#endif