Signed-off-by: Yoshinori Sato ysato@users.sourceforge.jp --- libc/misc/dirent/__readdir.c | 39 ++++++++++++++++++++++++++++++++++++++ libc/misc/dirent/readdir.c | 45 ++++---------------------------------------- libc/misc/dirent/readdir64.c | 12 ++++++++++-- 3 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 libc/misc/dirent/__readdir.c
diff --git a/libc/misc/dirent/__readdir.c b/libc/misc/dirent/__readdir.c new file mode 100644 index 0000000..18f6d79 --- /dev/null +++ b/libc/misc/dirent/__readdir.c @@ -0,0 +1,39 @@ +__DIRENT_TYPE *__READDIR(DIR * dir) +{ + ssize_t bytes; + __DIRENT_TYPE *de; + + if (!dir) { + __set_errno(EBADF); + return NULL; + } + + __UCLIBC_MUTEX_LOCK(dir->dd_lock); + + do { + if (dir->dd_size <= dir->dd_nextloc) { + /* read dir->dd_max bytes of directory entries. */ + bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max); + if (bytes <= 0) { + de = NULL; + goto all_done; + } + dir->dd_size = bytes; + dir->dd_nextloc = 0; + } + + de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc); + + /* Am I right? H.J. */ + dir->dd_nextloc += de->d_reclen; + + /* We have to save the next offset here. */ + dir->dd_nextoff = de->d_off; + + /* Skip deleted files. */ + } while (de->d_ino == 0); + +all_done: + __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); + return de; +} diff --git a/libc/misc/dirent/readdir.c b/libc/misc/dirent/readdir.c index 7517106..b5a23bb 100644 --- a/libc/misc/dirent/readdir.c +++ b/libc/misc/dirent/readdir.c @@ -10,53 +10,16 @@ #include <stddef.h> #include "dirstream.h"
-#ifndef __READDIR +#if !defined __ARCH_HAS_DEPRECATED_SYSCALLS__ # define __READDIR readdir # define __DIRENT_TYPE struct dirent # define __GETDENTS __getdents -#endif - -__DIRENT_TYPE *__READDIR(DIR * dir) -{ - ssize_t bytes; - __DIRENT_TYPE *de; - - if (!dir) { - __set_errno(EBADF); - return NULL; - } - - __UCLIBC_MUTEX_LOCK(dir->dd_lock); - - do { - if (dir->dd_size <= dir->dd_nextloc) { - /* read dir->dd_max bytes of directory entries. */ - bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max); - if (bytes <= 0) { - de = NULL; - goto all_done; - } - dir->dd_size = bytes; - dir->dd_nextloc = 0; - } - - de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc); - - /* Am I right? H.J. */ - dir->dd_nextloc += de->d_reclen; - - /* We have to save the next offset here. */ - dir->dd_nextoff = de->d_off;
- /* Skip deleted files. */ - } while (de->d_ino == 0); +# include "__readdir.c"
-all_done: - __UCLIBC_MUTEX_UNLOCK(dir->dd_lock); - return de; -} libc_hidden_def(__READDIR) -#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 +# if WORDSIZE == 64 strong_alias_untyped(readdir,readdir64) libc_hidden_def(readdir64) +# endif #endif diff --git a/libc/misc/dirent/readdir64.c b/libc/misc/dirent/readdir64.c index 17577a7..e16d6a1 100644 --- a/libc/misc/dirent/readdir64.c +++ b/libc/misc/dirent/readdir64.c @@ -6,11 +6,19 @@
#include <_lfs_64.h> #include <dirent.h> +#include <errno.h> +#define __need_NULL +#include <stddef.h> +#include "dirstream.h"
#if __WORDSIZE != 64 # define __READDIR readdir64 # define __DIRENT_TYPE struct dirent64 # define __GETDENTS __getdents64 - -# include "readdir.c" #endif + +# include "__readdir.c" + +libc_hidden_def(__READDIR) +strong_alias_untyped(readdir64,readdir) +libc_hidden_def(readdir)
Hi Yoshinori, Yoshinori Sato wrote,
Signed-off-by: Yoshinori Sato ysato@users.sourceforge.jp
libc/misc/dirent/__readdir.c | 39 ++++++++++++++++++++++++++++++++++++++ libc/misc/dirent/readdir.c | 45 ++++---------------------------------------- libc/misc/dirent/readdir64.c | 12 ++++++++++-- 3 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 libc/misc/dirent/__readdir.c
Did you find the issues you are solving in the four patches while code review or do you had runtime problems on a target?
Just to get a better understanding.
best regards Waldemar
On Sat, 02 Jan 2016 02:30:58 +0900, Waldemar Brodkorb wrote:
Hi Yoshinori, Yoshinori Sato wrote,
Signed-off-by: Yoshinori Sato ysato@users.sourceforge.jp
libc/misc/dirent/__readdir.c | 39 ++++++++++++++++++++++++++++++++++++++ libc/misc/dirent/readdir.c | 45 ++++---------------------------------------- libc/misc/dirent/readdir64.c | 12 ++++++++++-- 3 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 libc/misc/dirent/__readdir.c
Did you find the issues you are solving in the four patches while code review or do you had runtime problems on a target?
Yes. I tested only getdents64 system (not supported getdents syscall). It don't work glob in shell.
readir calld __getdents64. but it 2nd argument type dirent. kernel assume this type is dirent64 and write dirent64 structure. So type mismatch and can't parse result in readdir.
Just to get a better understanding.
best regards Waldemar
Hi Yoshinori, Yoshinori Sato wrote,
Signed-off-by: Yoshinori Sato ysato@users.sourceforge.jp
libc/misc/dirent/__readdir.c | 39 ++++++++++++++++++++++++++++++++++++++ libc/misc/dirent/readdir.c | 45 ++++---------------------------------------- libc/misc/dirent/readdir64.c | 12 ++++++++++-- 3 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 libc/misc/dirent/__readdir.c
While testing the patch I run into following issues. Alpha is the first architecture get tested ;)
/home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng_alpha/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/dirent/scandir64.c -o libc/misc/dirent/scandir64.os -Wall -Wstrict-pr ototypes -Wstrict-aliasing -funsigned-char -fno-builtin -fno-asm -fmerge-all-constants -std=gnu99 -fno-stack-protector -nostdinc -I./include -I./include -include libc-symbols.h -I./libc/sysd eps/linux/alpha -I./libc/sysdeps/linux -I./ldso/ldso/alpha -I./ldso/include -I. -DSTATIC -Os -fstrict-aliasing -fwrapv -fno-ident -fhonour-copts -static -Os -pipe -fomit-frame-pointer -fno-u nwind-tables -fno-asynchronous-unwind-tables -I./libpthread/linuxthreads.old/sysdeps/unix/sysv/linux/alpha -I./libpthread/linuxthreads.old/sysdeps/alpha -I./libpthread/linuxthreads.old/sysde ps/unix/sysv/linux -I./libpthread/linuxthreads.old/sysdeps/pthread -I./libpthread/linuxthreads.old -I./libpthread -I./libc/sysdeps/linux/common -isystem /home/wbx/embedded-test/openadk/toolc hain_qemu-alpha_uclibc-ng_alpha/usr/lib/gcc/alpha-openadk-linux-uclibc/5.3.0/include-fixed -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng_alpha/usr/lib/gcc/alpha-ope nadk-linux-uclibc/5.3.0/include -I/home/wbx/embedded-test/openadk/target_qemu-alpha_uclibc-ng_alpha/usr/include/ -DNDEBUG -DIN_LIB=libc -fPIC -MT libc/misc/dirent/scandir64.os -MD -MP -MF li bc/misc/dirent/.scandir64.os.dep In file included from libc/misc/dirent/readdir64.c:20:0: libc/misc/dirent/__readdir.c:1:1: error: unknown type name '__DIRENT_TYPE' __DIRENT_TYPE *__READDIR(DIR * dir) ^ libc/misc/dirent/__readdir.c: In function '__READDIR': libc/misc/dirent/__readdir.c:4:2: error: unknown type name '__DIRENT_TYPE' __DIRENT_TYPE *de; ^ libc/misc/dirent/__readdir.c:16:11: warning: implicit declaration of function '__GETDENTS' [-Wimplicit-function-declaration] bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max); ^ libc/misc/dirent/__readdir.c:25:12: error: '__DIRENT_TYPE' undeclared (first use in this function) de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc); ^ libc/misc/dirent/__readdir.c:25:12: note: each undeclared identifier is reported only once for each function it appears in libc/misc/dirent/__readdir.c:25:27: error: expected expression before ')' token de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc); ^ libc/misc/dirent/__readdir.c:28:27: error: request for member 'd_reclen' in something not a structure or union dir->dd_nextloc += de->d_reclen; ^ libc/misc/dirent/__readdir.c:31:26: error: request for member 'd_off' in something not a structure or union dir->dd_nextoff = de->d_off; ^ libc/misc/dirent/__readdir.c:34:13: error: request for member 'd_ino' in something not a structure or union } while (de->d_ino == 0); ^ In file included from <command-line>:0:0: libc/misc/dirent/readdir64.c: At top level: ./include/libc-symbols.h:426:25: error: '__EI___READDIR' aliased to undefined symbol '__GI___READDIR' extern __typeof (name) __EI_##name __attribute__((alias (__hidden_asmname1 (,#local)))) ^ ./include/libc-symbols.h:429:29: note: in expansion of macro '__hidden_ver1' # define hidden_def(name) __hidden_ver1(__GI_##name, name, name); ^ ./include/libc-symbols.h:497:32: note: in expansion of macro 'hidden_def' # define libc_hidden_def(name) hidden_def (name) ^ libc/misc/dirent/readdir64.c:22:1: note: in expansion of macro 'libc_hidden_def' ...
best regards Waldemar
On Fri, 08 Jan 2016 07:32:13 +0900, Waldemar Brodkorb wrote:
Hi Yoshinori, Yoshinori Sato wrote,
Signed-off-by: Yoshinori Sato ysato@users.sourceforge.jp
libc/misc/dirent/__readdir.c | 39 ++++++++++++++++++++++++++++++++++++++ libc/misc/dirent/readdir.c | 45 ++++---------------------------------------- libc/misc/dirent/readdir64.c | 12 ++++++++++-- 3 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 libc/misc/dirent/__readdir.c
While testing the patch I run into following issues. Alpha is the first architecture get tested ;)
/home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng_alpha/usr/bin/alpha-openadk-linux-uclibc-gcc -c libc/misc/dirent/scandir64.c -o libc/misc/dirent/scandir64.os -Wall -Wstrict-pr ototypes -Wstrict-aliasing -funsigned-char -fno-builtin -fno-asm -fmerge-all-constants -std=gnu99 -fno-stack-protector -nostdinc -I./include -I./include -include libc-symbols.h -I./libc/sysd eps/linux/alpha -I./libc/sysdeps/linux -I./ldso/ldso/alpha -I./ldso/include -I. -DSTATIC -Os -fstrict-aliasing -fwrapv -fno-ident -fhonour-copts -static -Os -pipe -fomit-frame-pointer -fno-u nwind-tables -fno-asynchronous-unwind-tables -I./libpthread/linuxthreads.old/sysdeps/unix/sysv/linux/alpha -I./libpthread/linuxthreads.old/sysdeps/alpha -I./libpthread/linuxthreads.old/sysde ps/unix/sysv/linux -I./libpthread/linuxthreads.old/sysdeps/pthread -I./libpthread/linuxthreads.old -I./libpthread -I./libc/sysdeps/linux/common -isystem /home/wbx/embedded-test/openadk/toolc hain_qemu-alpha_uclibc-ng_alpha/usr/lib/gcc/alpha-openadk-linux-uclibc/5.3.0/include-fixed -isystem /home/wbx/embedded-test/openadk/toolchain_qemu-alpha_uclibc-ng_alpha/usr/lib/gcc/alpha-ope nadk-linux-uclibc/5.3.0/include -I/home/wbx/embedded-test/openadk/target_qemu-alpha_uclibc-ng_alpha/usr/include/ -DNDEBUG -DIN_LIB=libc -fPIC -MT libc/misc/dirent/scandir64.os -MD -MP -MF li bc/misc/dirent/.scandir64.os.dep In file included from libc/misc/dirent/readdir64.c:20:0: libc/misc/dirent/__readdir.c:1:1: error: unknown type name '__DIRENT_TYPE' __DIRENT_TYPE *__READDIR(DIR * dir) ^ libc/misc/dirent/__readdir.c: In function '__READDIR': libc/misc/dirent/__readdir.c:4:2: error: unknown type name '__DIRENT_TYPE' __DIRENT_TYPE *de; ^ libc/misc/dirent/__readdir.c:16:11: warning: implicit declaration of function '__GETDENTS' [-Wimplicit-function-declaration] bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max); ^ libc/misc/dirent/__readdir.c:25:12: error: '__DIRENT_TYPE' undeclared (first use in this function) de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc); ^ libc/misc/dirent/__readdir.c:25:12: note: each undeclared identifier is reported only once for each function it appears in libc/misc/dirent/__readdir.c:25:27: error: expected expression before ')' token de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc); ^ libc/misc/dirent/__readdir.c:28:27: error: request for member 'd_reclen' in something not a structure or union dir->dd_nextloc += de->d_reclen; ^ libc/misc/dirent/__readdir.c:31:26: error: request for member 'd_off' in something not a structure or union dir->dd_nextoff = de->d_off; ^ libc/misc/dirent/__readdir.c:34:13: error: request for member 'd_ino' in something not a structure or union } while (de->d_ino == 0); ^ In file included from <command-line>:0:0: libc/misc/dirent/readdir64.c: At top level: ./include/libc-symbols.h:426:25: error: '__EI___READDIR' aliased to undefined symbol '__GI___READDIR' extern __typeof (name) __EI_##name __attribute__((alias (__hidden_asmname1 (,#local)))) ^ ./include/libc-symbols.h:429:29: note: in expansion of macro '__hidden_ver1' # define hidden_def(name) __hidden_ver1(__GI_##name, name, name); ^ ./include/libc-symbols.h:497:32: note: in expansion of macro 'hidden_def' # define libc_hidden_def(name) hidden_def (name) ^ libc/misc/dirent/readdir64.c:22:1: note: in expansion of macro 'libc_hidden_def' ...
best regards Waldemar
Sorry. my tree broken. Please ignore this.