[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/build/uClibc/libc/misc/dirent/Makefile b/ap/build/uClibc/libc/misc/dirent/Makefile
new file mode 100644
index 0000000..4a8f4a0
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/Makefile
@@ -0,0 +1,13 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+top_srcdir=../../../
+top_builddir=../../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.in
+include $(top_srcdir)Makerules
diff --git a/ap/build/uClibc/libc/misc/dirent/Makefile.in b/ap/build/uClibc/libc/misc/dirent/Makefile.in
new file mode 100644
index 0000000..d42dfeb
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/Makefile.in
@@ -0,0 +1,28 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+subdirs += libc/misc/dirent
+
+CSRC := alphasort.c closedir.c dirfd.c opendir.c readdir.c rewinddir.c \
+ scandir.c seekdir.c telldir.c readdir_r.c versionsort.c
+
+ifeq ($(UCLIBC_HAS_LFS),y)
+CSRC += readdir64.c alphasort64.c scandir64.c readdir64_r.c versionsort64.c
+endif
+
+MISC_DIRENT_DIR := $(top_srcdir)libc/misc/dirent
+MISC_DIRENT_OUT := $(top_builddir)libc/misc/dirent
+
+MISC_DIRENT_SRC := $(patsubst %.c,$(MISC_DIRENT_DIR)/%.c,$(CSRC))
+MISC_DIRENT_OBJ := $(patsubst %.c,$(MISC_DIRENT_OUT)/%.o,$(CSRC))
+
+libc-y += $(MISC_DIRENT_OBJ)
+
+objclean-y += CLEAN_libc/misc/dirent
+
+CLEAN_libc/misc/dirent:
+ $(do_rm) $(addprefix $(MISC_DIRENT_OUT)/*., o os)
diff --git a/ap/build/uClibc/libc/misc/dirent/alphasort.c b/ap/build/uClibc/libc/misc/dirent/alphasort.c
new file mode 100644
index 0000000..eb0dbf2
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/alphasort.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <string.h>
+#include "dirstream.h"
+
+int alphasort(const struct dirent **a, const struct dirent **b)
+{
+ return strcmp((*a)->d_name, (*b)->d_name);
+}
+
diff --git a/ap/build/uClibc/libc/misc/dirent/alphasort64.c b/ap/build/uClibc/libc/misc/dirent/alphasort64.c
new file mode 100644
index 0000000..d65b596
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/alphasort64.c
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <_lfs_64.h>
+
+#include <dirent.h>
+#include <string.h>
+#include "dirstream.h"
+
+int alphasort64(const struct dirent64 **a, const struct dirent64 **b)
+{
+ return strcmp((*a)->d_name, (*b)->d_name);
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/closedir.c b/ap/build/uClibc/libc/misc/dirent/closedir.c
new file mode 100644
index 0000000..dfb53f8
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/closedir.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "dirstream.h"
+#include <not-cancel.h>
+
+
+int closedir(DIR * dir)
+{
+ int fd;
+
+ if (!dir) {
+ __set_errno(EBADF);
+ return -1;
+ }
+
+ /* We need to check dd_fd. */
+ if (dir->dd_fd == -1) {
+ __set_errno(EBADF);
+ return -1;
+ }
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
+ fd = dir->dd_fd;
+ dir->dd_fd = -1;
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
+ free(dir->dd_buf);
+ free(dir);
+ return close_not_cancel(fd);
+}
+libc_hidden_def(closedir)
diff --git a/ap/build/uClibc/libc/misc/dirent/dirfd.c b/ap/build/uClibc/libc/misc/dirent/dirfd.c
new file mode 100644
index 0000000..649dd4a
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/dirfd.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include "dirstream.h"
+
+
+int dirfd(DIR * dir)
+{
+ if (!dir || dir->dd_fd == -1) {
+ __set_errno(EBADF);
+ return -1;
+ }
+
+ return dir->dd_fd;
+}
+libc_hidden_def(dirfd)
diff --git a/ap/build/uClibc/libc/misc/dirent/dirstream.h b/ap/build/uClibc/libc/misc/dirent/dirstream.h
new file mode 100644
index 0000000..370886a
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/dirstream.h
@@ -0,0 +1,74 @@
+/* Copyright (C) 1991, 1992 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+/*
+ * POSIX Standard: 5.1.2 Directory Operations <dirent.h>
+ */
+
+#ifndef _DIRSTREAM_H
+
+#define _DIRSTREAM_H 1
+
+#include <features.h>
+#include <sys/types.h>
+
+#include <bits/uClibc_mutex.h>
+
+/* For now, syscall readdir () only supports one entry at a time. It
+ * will be changed in the future.
+#define NUMENT 3
+*/
+#ifndef NUMENT
+#define NUMENT 1
+#endif
+
+#define SINGLE_READDIR 11
+#define MULTI_READDIR 12
+#define NEW_READDIR 13
+
+/* Directory stream type. */
+struct __dirstream {
+ /* file descriptor */
+ int dd_fd;
+
+ /* offset of the next dir entry in buffer */
+ size_t dd_nextloc;
+
+ /* bytes of valid entries in buffer */
+ size_t dd_size;
+
+ /* -> directory buffer */
+ void *dd_buf;
+
+ /* offset of the next dir entry in directory. */
+ off_t dd_nextoff;
+
+ /* total size of buffer */
+ size_t dd_max;
+
+ /* lock */
+ __UCLIBC_MUTEX(dd_lock);
+}; /* stream data from opendir() */
+
+
+extern ssize_t __getdents(int fd, char *buf, size_t count) attribute_hidden;
+#ifdef __UCLIBC_HAS_LFS__
+extern ssize_t __getdents64 (int fd, char *buf, size_t count) attribute_hidden;
+#endif
+
+#endif /* dirent.h */
diff --git a/ap/build/uClibc/libc/misc/dirent/opendir.c b/ap/build/uClibc/libc/misc/dirent/opendir.c
new file mode 100644
index 0000000..66a5cc9
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/opendir.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/dir.h>
+#include <sys/stat.h>
+#include <not-cancel.h>
+#include <dirent.h>
+#include "dirstream.h"
+
+static DIR *fd_to_DIR(int fd, __blksize_t size)
+{
+ DIR *ptr;
+
+ ptr = malloc(sizeof(*ptr));
+ if (!ptr)
+ return NULL;
+
+ ptr->dd_fd = fd;
+ ptr->dd_nextloc = ptr->dd_size = ptr->dd_nextoff = 0;
+ ptr->dd_max = size;
+ if (ptr->dd_max < 512)
+ ptr->dd_max = 512;
+
+ ptr->dd_buf = calloc(1, ptr->dd_max);
+ if (!ptr->dd_buf) {
+ free(ptr);
+ return NULL;
+ }
+ __UCLIBC_MUTEX_INIT_VAR(ptr->dd_lock);
+
+ return ptr;
+}
+
+DIR *fdopendir(int fd)
+{
+ int flags;
+ struct stat st;
+
+ if (fstat(fd, &st))
+ return NULL;
+ if (!S_ISDIR(st.st_mode)) {
+ __set_errno(ENOTDIR);
+ return NULL;
+ }
+
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1)
+ return NULL;
+ if ((flags & O_ACCMODE) == O_WRONLY) {
+ __set_errno(EINVAL);
+ return NULL;
+ }
+
+ return fd_to_DIR(fd, st.st_blksize);
+}
+
+/* opendir just makes an open() call - it return NULL if it fails
+ * (open sets errno), otherwise it returns a DIR * pointer.
+ */
+DIR *opendir(const char *name)
+{
+ int fd;
+ struct stat statbuf;
+ DIR *ptr;
+
+#ifndef O_DIRECTORY
+ /* O_DIRECTORY is linux specific and has been around since like 2.1.x */
+ if (stat(name, &statbuf))
+ return NULL;
+ if (!S_ISDIR(statbuf.st_mode)) {
+ __set_errno(ENOTDIR);
+ return NULL;
+ }
+# define O_DIRECTORY 0
+#endif
+ fd = open_not_cancel_2(name, O_RDONLY|O_NDELAY|O_DIRECTORY|O_CLOEXEC);
+ if (fd < 0)
+ return NULL;
+ /* Note: we should check to make sure that between the stat() and open()
+ * call, 'name' didnt change on us, but that's only if O_DIRECTORY isnt
+ * defined and since Linux has supported it for like ever, i'm not going
+ * to worry about it right now (if ever). */
+
+ if (fstat(fd, &statbuf) < 0) {
+ /* this close() never fails
+ *int saved_errno;
+ *saved_errno = errno; */
+ close_not_cancel_no_status(fd);
+ /*__set_errno(saved_errno);*/
+ return NULL;
+ }
+
+ /* According to POSIX, directory streams should be closed when
+ * exec. From "Anna Pluzhnikov" <besp@midway.uchicago.edu>.
+ */
+#ifndef __ASSUME_O_CLOEXEC
+ fcntl_not_cancel(fd, F_SETFD, FD_CLOEXEC);
+#endif
+
+ ptr = fd_to_DIR(fd, statbuf.st_blksize);
+
+ if (!ptr) {
+ close_not_cancel_no_status(fd);
+ __set_errno(ENOMEM);
+ }
+ return ptr;
+}
+libc_hidden_def(opendir)
diff --git a/ap/build/uClibc/libc/misc/dirent/readdir.c b/ap/build/uClibc/libc/misc/dirent/readdir.c
new file mode 100644
index 0000000..4fcd1cc
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/readdir.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <features.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "dirstream.h"
+
+
+struct dirent *readdir(DIR * dir)
+{
+ ssize_t bytes;
+ struct dirent *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 = (struct dirent *) (((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;
+}
+libc_hidden_def(readdir)
diff --git a/ap/build/uClibc/libc/misc/dirent/readdir64.c b/ap/build/uClibc/libc/misc/dirent/readdir64.c
new file mode 100644
index 0000000..1264c38
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/readdir64.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <_lfs_64.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "dirstream.h"
+
+struct dirent64 *readdir64(DIR * dir)
+{
+ ssize_t bytes;
+ struct dirent64 *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 = __getdents64(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 = (struct dirent64 *) (((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;
+}
+libc_hidden_def(readdir64)
diff --git a/ap/build/uClibc/libc/misc/dirent/readdir64_r.c b/ap/build/uClibc/libc/misc/dirent/readdir64_r.c
new file mode 100644
index 0000000..ba72600
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/readdir64_r.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <_lfs_64.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "dirstream.h"
+
+
+int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result)
+{
+ int ret;
+ ssize_t bytes;
+ struct dirent64 *de;
+
+ if (!dir) {
+ __set_errno(EBADF);
+ return(EBADF);
+ }
+ de = NULL;
+
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
+
+ do {
+ if (dir->dd_size <= dir->dd_nextloc) {
+ /* read dir->dd_max bytes of directory entries. */
+ bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
+ if (bytes <= 0) {
+ *result = NULL;
+ ret = (bytes==0)? 0 : errno;
+ goto all_done;
+ }
+ dir->dd_size = bytes;
+ dir->dd_nextloc = 0;
+ }
+
+ de = (struct dirent64 *) (((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);
+
+ if (de == NULL) {
+ *result = NULL;
+ } else {
+ *result = memcpy (entry, de, de->d_reclen);
+ }
+ ret = 0;
+
+all_done:
+
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
+ return((de != NULL)? 0 : ret);
+}
+libc_hidden_def(readdir64_r)
diff --git a/ap/build/uClibc/libc/misc/dirent/readdir_r.c b/ap/build/uClibc/libc/misc/dirent/readdir_r.c
new file mode 100644
index 0000000..d08997f
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/readdir_r.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "dirstream.h"
+
+
+int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
+{
+ int ret;
+ ssize_t bytes;
+ struct dirent *de;
+
+ if (!dir) {
+ __set_errno(EBADF);
+ return(EBADF);
+ }
+ de = 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) {
+ *result = NULL;
+ ret = (bytes==0)? 0 : errno;
+ goto all_done;
+ }
+ dir->dd_size = bytes;
+ dir->dd_nextloc = 0;
+ }
+
+ de = (struct dirent *) (((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);
+
+ if (de == NULL) {
+ *result = NULL;
+ } else {
+ *result = memcpy (entry, de, de->d_reclen);
+ }
+ ret = 0;
+
+all_done:
+
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
+ return((de != NULL)? 0 : ret);
+}
+libc_hidden_def(readdir_r)
diff --git a/ap/build/uClibc/libc/misc/dirent/rewinddir.c b/ap/build/uClibc/libc/misc/dirent/rewinddir.c
new file mode 100644
index 0000000..0a8f147
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/rewinddir.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include "dirstream.h"
+
+
+/* rewinddir() just does an lseek(fd,0,0) - see close for comments */
+void rewinddir(DIR * dir)
+{
+ if (!dir) {
+ __set_errno(EBADF);
+ return;
+ }
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
+ lseek(dir->dd_fd, 0, SEEK_SET);
+ dir->dd_nextoff = dir->dd_nextloc = dir->dd_size = 0;
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/scandir.c b/ap/build/uClibc/libc/misc/dirent/scandir.c
new file mode 100644
index 0000000..bb42564
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/scandir.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "dirstream.h"
+
+int scandir(const char *dir, struct dirent ***namelist,
+ int (*selector) (const struct dirent *),
+ int (*compar) (const struct dirent **, const struct dirent **))
+{
+ DIR *dp = opendir (dir);
+ struct dirent *current;
+ struct dirent **names = NULL;
+ size_t names_size = 0, pos;
+ int save;
+
+ if (dp == NULL)
+ return -1;
+
+ save = errno;
+ __set_errno (0);
+
+ pos = 0;
+ while ((current = readdir (dp)) != NULL) {
+ int use_it = selector == NULL;
+
+ if (! use_it)
+ {
+ use_it = (*selector) (current);
+ /* The selector function might have changed errno.
+ * It was zero before and it need to be again to make
+ * the latter tests work. */
+ if (! use_it)
+ __set_errno (0);
+ }
+ if (use_it)
+ {
+ struct dirent *vnew;
+ size_t dsize;
+
+ /* Ignore errors from selector or readdir */
+ __set_errno (0);
+
+ if (unlikely(pos == names_size))
+ {
+ struct dirent **new;
+ if (names_size == 0)
+ names_size = 10;
+ else
+ names_size *= 2;
+ new = (struct dirent **) realloc (names,
+ names_size * sizeof (struct dirent *));
+ if (new == NULL)
+ break;
+ names = new;
+ }
+
+ dsize = ¤t->d_name[_D_ALLOC_NAMLEN(current)] - (char*)current;
+ vnew = (struct dirent *) malloc (dsize);
+ if (vnew == NULL)
+ break;
+
+ names[pos++] = (struct dirent *) memcpy (vnew, current, dsize);
+ }
+ }
+
+ if (unlikely(errno != 0))
+ {
+ save = errno;
+ closedir (dp);
+ while (pos > 0)
+ free (names[--pos]);
+ free (names);
+ __set_errno (save);
+ return -1;
+ }
+
+ closedir (dp);
+ __set_errno (save);
+
+ /* Sort the list if we have a comparison function to sort with. */
+ if (compar != NULL)
+ qsort (names, pos, sizeof (struct dirent *), (comparison_fn_t) compar);
+ *namelist = names;
+ return pos;
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/scandir64.c b/ap/build/uClibc/libc/misc/dirent/scandir64.c
new file mode 100644
index 0000000..3d2a250
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/scandir64.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 1992-1998, 2000 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+ */
+
+/* Modified for uClibc by Erik Andersen
+ */
+
+#include <_lfs_64.h>
+
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "dirstream.h"
+
+int scandir64(const char *dir, struct dirent64 ***namelist,
+ int (*selector) (const struct dirent64 *),
+ int (*compar) (const struct dirent64 **, const struct dirent64 **))
+{
+ DIR *dp = opendir (dir);
+ struct dirent64 *current;
+ struct dirent64 **names = NULL;
+ size_t names_size = 0, pos;
+ int save;
+
+ if (dp == NULL)
+ return -1;
+
+ save = errno;
+ __set_errno (0);
+
+ pos = 0;
+ while ((current = readdir64 (dp)) != NULL) {
+ int use_it = selector == NULL;
+
+ if (! use_it)
+ {
+ use_it = (*selector) (current);
+ /* The selector function might have changed errno.
+ * It was zero before and it need to be again to make
+ * the latter tests work. */
+ if (! use_it)
+ __set_errno (0);
+ }
+ if (use_it)
+ {
+ struct dirent64 *vnew;
+ size_t dsize;
+
+ /* Ignore errors from selector or readdir64 */
+ __set_errno (0);
+
+ if (unlikely(pos == names_size))
+ {
+ struct dirent64 **new;
+ if (names_size == 0)
+ names_size = 10;
+ else
+ names_size *= 2;
+ new = (struct dirent64 **) realloc (names,
+ names_size * sizeof (struct dirent64 *));
+ if (new == NULL)
+ break;
+ names = new;
+ }
+
+ dsize = ¤t->d_name[_D_ALLOC_NAMLEN(current)] - (char*)current;
+ vnew = (struct dirent64 *) malloc (dsize);
+ if (vnew == NULL)
+ break;
+
+ names[pos++] = (struct dirent64 *) memcpy (vnew, current, dsize);
+ }
+ }
+ if (unlikely(errno != 0))
+ {
+ save = errno;
+ closedir (dp);
+ while (pos > 0)
+ free (names[--pos]);
+ free (names);
+ __set_errno (save);
+ return -1;
+ }
+
+ closedir (dp);
+ __set_errno (save);
+
+ /* Sort the list if we have a comparison function to sort with. */
+ if (compar != NULL)
+ qsort (names, pos, sizeof (struct dirent64 *), (comparison_fn_t) compar);
+ *namelist = names;
+ return pos;
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/seekdir.c b/ap/build/uClibc/libc/misc/dirent/seekdir.c
new file mode 100644
index 0000000..eaf447e
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/seekdir.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include "dirstream.h"
+
+
+void seekdir(DIR * dir, long int offset)
+{
+ if (!dir) {
+ __set_errno(EBADF);
+ return;
+ }
+ __UCLIBC_MUTEX_LOCK(dir->dd_lock);
+ dir->dd_nextoff = lseek(dir->dd_fd, offset, SEEK_SET);
+ dir->dd_size = dir->dd_nextloc = 0;
+ __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/telldir.c b/ap/build/uClibc/libc/misc/dirent/telldir.c
new file mode 100644
index 0000000..3c5deca
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/telldir.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include "dirstream.h"
+
+
+long int telldir(DIR * dir)
+{
+ if (!dir) {
+ __set_errno(EBADF);
+ return -1;
+ }
+
+ /* The next entry. */
+ return dir->dd_nextoff;
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/versionsort.c b/ap/build/uClibc/libc/misc/dirent/versionsort.c
new file mode 100644
index 0000000..d84da1f
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/versionsort.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2008-2009 Hai Zaar, Codefidence Ltd <haizaar@codefidence.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <dirent.h>
+#include <string.h>
+#include "dirstream.h"
+
+int versionsort(const struct dirent **a, const struct dirent **b)
+{
+ return strverscmp((*a)->d_name, (*b)->d_name);
+}
diff --git a/ap/build/uClibc/libc/misc/dirent/versionsort64.c b/ap/build/uClibc/libc/misc/dirent/versionsort64.c
new file mode 100644
index 0000000..af9689e
--- /dev/null
+++ b/ap/build/uClibc/libc/misc/dirent/versionsort64.c
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2008-2009 Hai Zaar, Codefidence Ltd <haizaar@codefidence.com>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <_lfs_64.h>
+
+#include <dirent.h>
+#include <string.h>
+#include "dirstream.h"
+
+int versionsort64(const struct dirent64 **a, const struct dirent64 **b)
+{
+ return strverscmp((*a)->d_name, (*b)->d_name);
+}