public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] generic/wordsize-32: don't declare getdents() if not needed
@ 2016-09-19 16:57 Yury Norov
  2016-10-25 20:46 ` Yury Norov
  0 siblings, 1 reply; 2+ messages in thread
From: Yury Norov @ 2016-09-19 16:57 UTC (permalink / raw)
  To: libc-alpha; +Cc: Yury Norov


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(-)

diff --git a/sysdeps/unix/sysv/linux/bits/dirent.h b/sysdeps/unix/sysv/linux/bits/dirent.h
index 31b1961..23b7e6f 100644
--- a/sysdeps/unix/sysv/linux/bits/dirent.h
+++ b/sysdeps/unix/sysv/linux/bits/dirent.h
@@ -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
diff --git a/sysdeps/unix/sysv/linux/generic/getdents64.c b/sysdeps/unix/sysv/linux/generic/getdents64.c
index 3e44699..a9b63a3 100644
--- a/sysdeps/unix/sysv/linux/generic/getdents64.c
+++ b/sysdeps/unix/sysv/linux/generic/getdents64.c
@@ -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
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
index bc3a80e..7d2fbe6 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c
@@ -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
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] generic/wordsize-32: don't declare getdents() if not needed
  2016-09-19 16:57 [PATCH] generic/wordsize-32: don't declare getdents() if not needed Yury Norov
@ 2016-10-25 20:46 ` Yury Norov
  0 siblings, 0 replies; 2+ messages in thread
From: Yury Norov @ 2016-10-25 20:46 UTC (permalink / raw)
  To: libc-alpha

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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-25 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-19 16:57 [PATCH] generic/wordsize-32: don't declare getdents() if not needed Yury Norov
2016-10-25 20:46 ` Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).