summaryrefslogtreecommitdiff
path: root/libc/misc/dirent/readdir_r.c
diff options
context:
space:
mode:
authorPeter S. Mazinger <ps.m@gmx.net>2011-03-16 21:07:18 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-06-15 14:00:25 +0200
commitbef4efb18c54f4b2285557a1b5a5a037f3dce019 (patch)
treecc51a00e5200f2441e5cf3b9e9d2088726029e0d /libc/misc/dirent/readdir_r.c
parente50a776d7615173ede86f5f492bed5d2b75214ec (diff)
scandir,readdir[_t]: use one common source for X() and X64()
Since the sources differ only minimally, use only scandir.c,readdir[_t].c and redefine the used functions accordingly. Use a strong_alias instead of compiling *64.c if __WORDSIZE = 64 Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/misc/dirent/readdir_r.c')
-rw-r--r--libc/misc/dirent/readdir_r.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/libc/misc/dirent/readdir_r.c b/libc/misc/dirent/readdir_r.c
index d08997ffa..7cdc0aba1 100644
--- a/libc/misc/dirent/readdir_r.c
+++ b/libc/misc/dirent/readdir_r.c
@@ -4,19 +4,24 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
+#include <dirent.h>
#include <errno.h>
-#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
+#define __need_NULL
+#include <stddef.h>
#include "dirstream.h"
+#ifndef __READDIR_R
+# define __READDIR_R readdir_r
+# define __DIRENT_TYPE struct dirent
+# define __GETDENTS __getdents
+#endif
-int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
+int __READDIR_R(DIR *dir, __DIRENT_TYPE *entry, __DIRENT_TYPE **result)
{
int ret;
ssize_t bytes;
- struct dirent *de;
+ __DIRENT_TYPE *de;
if (!dir) {
__set_errno(EBADF);
@@ -29,7 +34,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
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);
+ bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes <= 0) {
*result = NULL;
ret = (bytes==0)? 0 : errno;
@@ -39,7 +44,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
dir->dd_nextloc = 0;
}
- de = (struct dirent *) (((char *) dir->dd_buf) + dir->dd_nextloc);
+ de = (__DIRENT_TYPE *) (((char *) dir->dd_buf) + dir->dd_nextloc);
/* Am I right? H.J. */
dir->dd_nextloc += de->d_reclen;
@@ -61,4 +66,8 @@ all_done:
__UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
return((de != NULL)? 0 : ret);
}
-libc_hidden_def(readdir_r)
+libc_hidden_def(__READDIR_R)
+#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
+strong_alias_untyped(readdir_r,readdir64_r)
+libc_hidden_def(readdir64_r)
+#endif