summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--StdLib/Include/dirent.h86
-rw-r--r--StdLib/Include/stdio.h2
-rw-r--r--StdLib/Include/sys/dirent.h66
-rw-r--r--StdLib/Include/sys/stat.h2
-rw-r--r--StdLib/LibC/Main/Arm/flt_rounds.c2
-rw-r--r--StdLib/LibC/Stdio/Stdio.inf1
-rw-r--r--StdLib/LibC/Stdio/tempnam.c2
-rw-r--r--StdLib/PosixLib/Gen/LibGen.inf4
-rw-r--r--StdLib/PosixLib/Gen/closedir.c88
-rw-r--r--StdLib/PosixLib/Gen/opendir.c136
-rw-r--r--StdLib/PosixLib/Gen/readdir.c138
-rw-r--r--StdLib/PosixLib/Glob/LibGlob.inf1
-rw-r--r--StdLib/PosixLib/Glob/glob.c1
-rw-r--r--StdLibPrivateInternalFiles/Include/extern.h22
14 files changed, 523 insertions, 28 deletions
diff --git a/StdLib/Include/dirent.h b/StdLib/Include/dirent.h
index 859f4d5aeb..d67a9e7bfb 100644
--- a/StdLib/Include/dirent.h
+++ b/StdLib/Include/dirent.h
@@ -4,7 +4,7 @@
The information is based upon the EFI_FILE_INFO structure
in MdePkg/Include/Guid/FileInfo.h.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -13,10 +13,94 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ Copyright (c) 1989, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: dirent.h,v 1.30 2008/01/09 20:55:03 christos Exp
+ @(#)dirent.h 8.2 (Berkeley) 7/28/94
**/
#ifndef _DIRENT_H_
#define _DIRENT_H_
+#include <sys/featuretest.h>
+#include <sys/types.h>
+
#include <sys/dirent.h>
+typedef struct _dirdesc DIR;
+
+/* definitions for library routines operating on directories. */
+#define DIRBLKSIZ 1024
+
+/* structure describing an open directory. */
+struct _dirdesc {
+ int dd_fd; /* file descriptor associated with directory */
+ long dd_loc; /* offset in current buffer */
+ long dd_size; /* amount of data returned by getdents */
+ char *dd_buf; /* data buffer */
+ int dd_len; /* size of data buffer */
+ off_t dd_seek; /* magic cookie returned by getdents */
+ void *dd_internal; /* state for seekdir/telldir */
+ int dd_flags; /* flags for readdir */
+ void *dd_lock; /* lock for concurrent access */
+};
+
+#define dirfd(dirp) ((dirp)->dd_fd)
+
+/* flags for __opendir2() */
+#define DTF_HIDEW 0x0001 /* hide whiteout entries */
+#define DTF_NODUP 0x0002 /* don't return duplicate names */
+#define DTF_REWIND 0x0004 /* rewind after reading union stack */
+#define __DTF_READALL 0x0008 /* everything has been read */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+ int closedir(DIR *);
+ void rewinddir(DIR *);
+
+ DIR *opendir(const char *) __RENAME(__opendir30);
+ struct dirent *readdir(DIR *) __RENAME(__readdir30);
+ int readdir_r(DIR * __restrict, struct dirent * __restrict,
+ struct dirent ** __restrict) __RENAME(__readdir_r30);
+
+ void seekdir(DIR *, long);
+ long telldir(DIR *);
+ DIR *__opendir2(const char *, int) __RENAME(__opendir230);
+
+ //#ifndef __LIBC12_SOURCE__
+ //int scandir(const char *, struct dirent ***,
+ // int (*)(const struct dirent *), int (*)(const void *,
+ // const void *)) __RENAME(__scandir30);
+ //int getdents(int, char *, size_t) __RENAME(__getdents30);
+ //#endif
+
+ //int alphasort(const void *, const void *);
+__END_DECLS
+
+
#endif /* _DIRENT_H_ */
diff --git a/StdLib/Include/stdio.h b/StdLib/Include/stdio.h
index 666e190df1..59022666bd 100644
--- a/StdLib/Include/stdio.h
+++ b/StdLib/Include/stdio.h
@@ -1496,7 +1496,7 @@ __BEGIN_DECLS
int mkstemp(char *);
char *mktemp(char *);
- char *tempnam(const char *, const char *);
+ char *tempnam(const char *, const char *);
__END_DECLS
/*
diff --git a/StdLib/Include/sys/dirent.h b/StdLib/Include/sys/dirent.h
index 14c67ae128..64b46e4d46 100644
--- a/StdLib/Include/sys/dirent.h
+++ b/StdLib/Include/sys/dirent.h
@@ -59,18 +59,22 @@
*
* All names are wide characters and are guaranteed to be null terminated.
* The maximum length of a name in a directory is MAXNAMLEN.
+ *
+ * This structure is identical to the EFI_FILE_INFO structure. A new
+ * structure is declared because one must be able to refer to it
+ * as struct dirent.
*/
struct dirent {
- UINT64 Size; // Size of this dirent structure instance,
- // including the Null-terminated FileName string.
- UINT64 FileSize; // The size of the file in bytes.
- UINT64 PhysicalSize; // The amount of physical space the file consumes
- // on the file system volume.
- UINT64 Attribute; // The time the file was created.
- struct timespec CreateTime; // The time when the file was last accessed.
- struct timespec LastAccessTime; // The time when the file's contents were last modified.
- struct timespec ModificationTime; // The attribute bits for the file. See below.
- CHAR16 FileName[1]; // The Null-terminated name of the file.
+ UINT64 Size; // (d_reclen) Size of this dirent structure instance,
+ // including the Null-terminated FileName string.
+ UINT64 FileSize; // The size of the file in bytes.
+ UINT64 PhysicalSize; // The amount of physical space the file consumes
+ // on the file system volume.
+ struct timespec CreateTime; // The time the file was created.
+ struct timespec LastAccessTime; // The time when the file was last accessed.
+ struct timespec ModificationTime; // The time when the file's contents were last modified.
+ UINT64 Attribute; // (d_type) The attribute bits for the file. See below.
+ CHAR16 FileName[1]; // (d_name) The Null-terminated name of the file.
};
/*
@@ -88,4 +92,46 @@ struct dirent {
#define DT_SOCKET 0x0000000000030000 // File attaches to a socket
#define DT_VALID_ATTR 0x0000000000030037 // Mask for valid attribute bits
+/*
+ * The _DIRENT_ALIGN macro returns the alignment of struct dirent.
+ * struct dirent uses 8.
+ */
+#define _DIRENT_ALIGN(dp) (sizeof((dp)->Size) - 1)
+
+/*
+ * The _DIRENT_NAMEOFF macro returns the offset of the d_name field in
+ * struct dirent
+ */
+#define _DIRENT_NAMEOFF(dp) \
+ ((char *)(void *)&(dp)->FileName - (char *)(void *)dp)
+
+/*
+ * The _DIRENT_RECLEN macro gives the minimum record length which will hold
+ * a name of size "namlen". This requires the amount of space in struct dirent
+ * without the d_name field, plus enough space for the name with a terminating
+ * null byte (namlen+1), rounded up to a the appropriate byte boundary.
+ */
+#define _DIRENT_RECLEN(dp, namlen) \
+ ((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_ALIGN(dp)) & \
+ ~_DIRENT_ALIGN(dp))
+
+#define _DIRENT_NAMELEN(dp) \
+ ((dp)->Size - _DIRENT_NAMEOFF(dp) - 1)
+
+/*
+ * The _DIRENT_SIZE macro returns the minimum record length required for
+ * name name stored in the current record.
+ */
+#define _DIRENT_SIZE(dp) _DIRENT_RECLEN(dp, _DIRENT_NAMELEN(dp))
+
+/*
+ * The _DIRENT_NEXT macro advances to the next dirent record.
+ */
+#define _DIRENT_NEXT(dp) ((void *)((char *)(void *)(dp) + (dp)->Size))
+
+/*
+ * The _DIRENT_MINSIZE returns the size of an empty (invalid) record.
+ */
+#define _DIRENT_MINSIZE(dp) _DIRENT_RECLEN(dp, 0)
+
#endif /* !_SYS_DIRENT_H_ */
diff --git a/StdLib/Include/sys/stat.h b/StdLib/Include/sys/stat.h
index 9330a2be04..f95385877a 100644
--- a/StdLib/Include/sys/stat.h
+++ b/StdLib/Include/sys/stat.h
@@ -183,7 +183,7 @@ __BEGIN_DECLS
/**
**/
- extern int stat (const char *, void *);
+ extern int stat (const char *, struct stat *);
/**
**/
diff --git a/StdLib/LibC/Main/Arm/flt_rounds.c b/StdLib/LibC/Main/Arm/flt_rounds.c
index a64f447aab..7e052cc337 100644
--- a/StdLib/LibC/Main/Arm/flt_rounds.c
+++ b/StdLib/LibC/Main/Arm/flt_rounds.c
@@ -43,7 +43,7 @@ static const int map[] = {
1, /* round to nearest */
2, /* round to positive infinity */
3, /* round to negative infinity */
- 0 /* round to zero */
+ 0 /* round to zero */
};
/*
diff --git a/StdLib/LibC/Stdio/Stdio.inf b/StdLib/LibC/Stdio/Stdio.inf
index 1b8852e0b5..a61a5584bf 100644
--- a/StdLib/LibC/Stdio/Stdio.inf
+++ b/StdLib/LibC/Stdio/Stdio.inf
@@ -62,6 +62,7 @@
setvbuf.c #
sprintf.c #
sscanf.c #
+ tempnam.c #
tmpfile.c #
tmpnam.c #
ungetc.c #
diff --git a/StdLib/LibC/Stdio/tempnam.c b/StdLib/LibC/Stdio/tempnam.c
index 368da844d0..f9df427c52 100644
--- a/StdLib/LibC/Stdio/tempnam.c
+++ b/StdLib/LibC/Stdio/tempnam.c
@@ -75,7 +75,7 @@ tempnam(const char *dir, const char *pfx)
char *name, *f;
const char *tmp;
- if (!(name = malloc((size_t)MAXPATHLEN)))
+ if ((name = malloc((size_t)MAXPATHLEN)) == NULL)
return NULL;
if (!pfx)
diff --git a/StdLib/PosixLib/Gen/LibGen.inf b/StdLib/PosixLib/Gen/LibGen.inf
index 276b2ee427..1fc20fe216 100644
--- a/StdLib/PosixLib/Gen/LibGen.inf
+++ b/StdLib/PosixLib/Gen/LibGen.inf
@@ -28,6 +28,9 @@
[Sources.common]
dirname.c
+ opendir.c
+ closedir.c
+ readdir.c
[Packages]
MdePkg/MdePkg.dec
@@ -35,6 +38,7 @@
StdLibPrivateInternalFiles/DoNotUse.dec
[Libraries]
+ LibStdio
LibString
LibStdLib
diff --git a/StdLib/PosixLib/Gen/closedir.c b/StdLib/PosixLib/Gen/closedir.c
new file mode 100644
index 0000000000..e5863b59ad
--- /dev/null
+++ b/StdLib/PosixLib/Gen/closedir.c
@@ -0,0 +1,88 @@
+/** @file
+ Close an open directory.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1993
+ Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: closedir.c,v 1.15 2006/05/17 20:36:50 christos Exp
+ closedir.c 8.1 (Berkeley) 6/10/93
+**/
+#include <sys/cdefs.h>
+
+#include <namespace.h>
+#include <reentrant.h>
+#include <extern.h>
+#include <sys/types.h>
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef __weak_alias
+__weak_alias(closedir,_closedir)
+#endif
+
+/*
+ * close a directory.
+ */
+int
+closedir(DIR *dirp)
+{
+ int fd;
+
+ _DIAGASSERT(dirp != NULL);
+
+#ifdef _REENTRANT
+ if (__isthreaded)
+ mutex_lock((mutex_t *)dirp->dd_lock);
+#endif
+ fd = dirp->dd_fd;
+ dirp->dd_fd = -1;
+ dirp->dd_loc = 0;
+ free(dirp->dd_buf);
+
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ mutex_unlock((mutex_t *)dirp->dd_lock);
+ mutex_destroy((mutex_t *)dirp->dd_lock);
+ free(dirp->dd_lock);
+ }
+#endif
+ free((void *)dirp);
+ return(close(fd));
+}
diff --git a/StdLib/PosixLib/Gen/opendir.c b/StdLib/PosixLib/Gen/opendir.c
new file mode 100644
index 0000000000..cb4ffbc477
--- /dev/null
+++ b/StdLib/PosixLib/Gen/opendir.c
@@ -0,0 +1,136 @@
+/** @file
+ Open a directory.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: opendir.c,v 1.33 2008/01/10 09:49:04 elad Exp
+ opendir.c 8.7 (Berkeley) 12/10/94
+**/
+#include <sys/cdefs.h>
+
+#include <namespace.h>
+#include <reentrant.h>
+#include <extern.h>
+#include <sys/param.h>
+//#include <sys/mount.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define MAXITERATIONS 100
+
+/*
+ * Open a directory.
+ */
+DIR *
+opendir(const char *name)
+{
+ _DIAGASSERT(name != NULL);
+
+ return (__opendir2(name, DTF_HIDEW|DTF_NODUP));
+}
+
+DIR *
+__opendir2(const char *name, int flags)
+{
+ DIR *dirp = NULL;
+ int fd;
+ int serrno;
+ struct stat sb;
+ int incr;
+
+ _DIAGASSERT(name != NULL);
+
+ if ((fd = open(name, O_RDONLY | O_NONBLOCK, 0)) == -1 ||
+ fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+ goto error;
+ if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
+ errno = ENOTDIR;
+ goto error;
+ }
+ if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)
+ goto error;
+ dirp->dd_buf = NULL;
+
+ /*
+ * If the machine's page size is an exact multiple of DIRBLKSIZ,
+ * use a buffer that is cluster boundary aligned.
+ * Hopefully this can be a big win someday by allowing page trades
+ * to user space to be done by getdirentries()
+ */
+ incr = DIRBLKSIZ;
+
+ dirp->dd_len = incr;
+ dirp->dd_buf = malloc((size_t)dirp->dd_len);
+ if (dirp->dd_buf == NULL)
+ goto error;
+ dirp->dd_seek = 0;
+ flags &= ~DTF_REWIND;
+
+ dirp->dd_loc = 0;
+ dirp->dd_fd = fd;
+ dirp->dd_flags = flags;
+
+ /*
+ * Set up seek point for rewinddir.
+ */
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ if ((dirp->dd_lock = malloc(sizeof(mutex_t))) == NULL)
+ goto error;
+ mutex_init((mutex_t *)dirp->dd_lock, NULL);
+ }
+#endif
+ dirp->dd_internal = NULL;
+ return (dirp);
+error:
+ serrno = errno;
+ if (dirp && dirp->dd_buf)
+ free(dirp->dd_buf);
+ if (dirp)
+ free(dirp);
+ if (fd != -1)
+ (void)close(fd);
+ errno = serrno;
+ return NULL;
+}
diff --git a/StdLib/PosixLib/Gen/readdir.c b/StdLib/PosixLib/Gen/readdir.c
new file mode 100644
index 0000000000..b8ad0af2a3
--- /dev/null
+++ b/StdLib/PosixLib/Gen/readdir.c
@@ -0,0 +1,138 @@
+/** @file
+ Get next entry in a directory.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Copyright (c) 1983, 1993
+ The Regents of the University of California. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the University nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+ NetBSD: readdir.c,v 1.24 2008/05/04 18:53:26 tonnerre Exp
+ readdir.c 8.3 (Berkeley) 9/29/94
+ */
+#include <sys/cdefs.h>
+
+#include <namespace.h>
+#include <reentrant.h>
+#include <extern.h>
+#include <sys/param.h>
+#include <sys/stdint.h>
+
+#include <stdio.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/EfiSysCall.h>
+
+/*
+ * get next entry in a directory.
+ */
+struct dirent *
+_readdir_unlocked(DIR *dirp, int skipdeleted)
+{
+ struct dirent *dp;
+
+
+ for (;;) {
+ if (dirp->dd_loc >= dirp->dd_size) {
+ if (dirp->dd_flags & __DTF_READALL)
+ return (NULL);
+ dirp->dd_loc = 0;
+ }
+ if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) {
+ dirp->dd_size = (long)read(dirp->dd_fd, dirp->dd_buf, (size_t)dirp->dd_len);
+ if (dirp->dd_size <= 0)
+ return (NULL);
+ }
+ dp = (struct dirent *) (void *)(dirp->dd_buf + (size_t)dirp->dd_loc);
+ if ((intptr_t)dp & _DIRENT_ALIGN(dp))/* bogus pointer check */
+ return (NULL);
+ dirp->dd_loc += (long)dp->Size;
+ if ((dp->Attribute & DT_HIDDEN) && (dirp->dd_flags & DTF_HIDEW))
+ continue;
+ return (dp);
+ }
+}
+
+struct dirent *
+readdir(DIR *dirp)
+{
+ struct dirent *dp;
+
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ mutex_lock((mutex_t *)dirp->dd_lock);
+ dp = _readdir_unlocked(dirp, 1);
+ mutex_unlock((mutex_t *)dirp->dd_lock);
+ }
+ else
+#endif
+ dp = _readdir_unlocked(dirp, 1);
+ return (dp);
+}
+
+int
+readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
+{
+ struct dirent *dp;
+ int saved_errno;
+
+ saved_errno = errno;
+ errno = 0;
+#ifdef _REENTRANT
+ if (__isthreaded) {
+ mutex_lock((mutex_t *)dirp->dd_lock);
+ if ((dp = _readdir_unlocked(dirp, 1)) != NULL)
+ memcpy(entry, dp, (size_t)_DIRENT_SIZE(dp));
+ mutex_unlock((mutex_t *)dirp->dd_lock);
+ }
+ else
+#endif
+ if ((dp = _readdir_unlocked(dirp, 1)) != NULL)
+ memcpy(entry, dp, (size_t)_DIRENT_SIZE(dp));
+
+ if (errno != 0) {
+ if (dp == NULL)
+ return (errno);
+ } else
+ errno = saved_errno;
+
+ if (dp != NULL)
+ *result = entry;
+ else
+ *result = NULL;
+
+ return (0);
+}
diff --git a/StdLib/PosixLib/Glob/LibGlob.inf b/StdLib/PosixLib/Glob/LibGlob.inf
index 06404382b7..9e2674d215 100644
--- a/StdLib/PosixLib/Glob/LibGlob.inf
+++ b/StdLib/PosixLib/Glob/LibGlob.inf
@@ -27,7 +27,6 @@
#
[Sources.common]
- DirFunctions.c
glob.c
[Packages]
diff --git a/StdLib/PosixLib/Glob/glob.c b/StdLib/PosixLib/Glob/glob.c
index a6a2dc156e..e7556c226a 100644
--- a/StdLib/PosixLib/Glob/glob.c
+++ b/StdLib/PosixLib/Glob/glob.c
@@ -89,7 +89,6 @@
#include <string.h>
#include <unistd.h>
#include <sys/fcntl.h>
-#include "internal.h"
#ifdef HAVE_NBTOOL_CONFIG_H
#define NO_GETPW_R
diff --git a/StdLibPrivateInternalFiles/Include/extern.h b/StdLibPrivateInternalFiles/Include/extern.h
index ff37d1c0a4..fc39d52908 100644
--- a/StdLibPrivateInternalFiles/Include/extern.h
+++ b/StdLibPrivateInternalFiles/Include/extern.h
@@ -43,9 +43,9 @@ char *__dtoa(double, int, int, int *, int *, char **);
void __freedtoa(char *);
int __sysctl(const int *, unsigned int, void *, size_t *, const void *, size_t);
-struct sigaction;
-int __sigaction_sigtramp(int, const struct sigaction *,
- struct sigaction *, const void *, int);
+//struct sigaction;
+//int __sigaction_sigtramp(int, const struct sigaction *,
+// struct sigaction *, const void *, int);
#ifdef WIDE_DOUBLE
char *__hdtoa(double, const char *, int, int *, int *, char **);
@@ -53,15 +53,15 @@ int __sigaction_sigtramp(int, const struct sigaction *,
char *__ldtoa(long double *, int, int, int *, int *, char **);
#endif
-struct syslog_data;
-void syslog_ss(int, struct syslog_data *, const char *, ...)
- __attribute__((__format__(__printf__,3,4)));
-void vsyslog_ss(int, struct syslog_data *, const char *, _BSD_VA_LIST_);
+//struct syslog_data;
+//void syslog_ss(int, struct syslog_data *, const char *, ...)
+// __attribute__((__format__(__printf__,3,4)));
+//void vsyslog_ss(int, struct syslog_data *, const char *, _BSD_VA_LIST_);
-int snprintf_ss(char * __restrict, size_t, const char * __restrict, ...)
- __attribute__((__format__(__printf__, 3, 4)));
-int vsnprintf_ss(char * __restrict, size_t, const char * __restrict,
- _BSD_VA_LIST_) __attribute__((__format__(__printf__, 3, 0)));
+//int snprintf_ss(char * __restrict, size_t, const char * __restrict, ...)
+// __attribute__((__format__(__printf__, 3, 4)));
+//int vsnprintf_ss(char * __restrict, size_t, const char * __restrict,
+// _BSD_VA_LIST_) __attribute__((__format__(__printf__, 3, 0)));
void Efi2Tm( EFI_TIME *ET, struct tm *BT);
time_t Efi2Time( EFI_TIME *EfiBDtime);