summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred Perlstein <alfred@FreeBSD.org>1999-11-29 19:12:50 +0000
committerAlfred Perlstein <alfred@FreeBSD.org>1999-11-29 19:12:50 +0000
commit8b6c02f328e21efda4d5de8c79d8b553e8b4ce2f (patch)
tree16ee8b855ef353393708518caa8c119b0dadcc31
parent6c48b6cf75960ede12a39f91a6c87ad709c6c47e (diff)
Notes
-rw-r--r--include/dirent.h4
-rw-r--r--lib/libc/gen/readdir.c37
2 files changed, 21 insertions, 20 deletions
diff --git a/include/dirent.h b/include/dirent.h
index f36b44f1f416..7dc16e766f88 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -31,9 +31,7 @@
* SUCH DAMAGE.
*
* @(#)dirent.h 8.2 (Berkeley) 7/28/94
- *
* $FreeBSD$
- *
*/
#ifndef _DIRENT_H_
@@ -97,8 +95,8 @@ int scandir __P((const char *, struct dirent ***,
int (*)(struct dirent *), int (*)(const void *, const void *)));
int alphasort __P((const void *, const void *));
int getdirentries __P((int, char *, int, long *));
-#endif /* not POSIX */
int readdir_r __P((DIR *, struct dirent *, struct dirent **));
+#endif /* not POSIX */
__END_DECLS
#endif /* !KERNEL */
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index 9b8c1758554a..2e91a9ac2448 100644
--- a/lib/libc/gen/readdir.c
+++ b/lib/libc/gen/readdir.c
@@ -89,34 +89,37 @@ readdir_r(dirp, entry, result)
struct dirent **result;
{
struct dirent *dp;
- int ret;
+ int ret, saved_errno;
- if (dirp->dd_fd < 0) {
- return EBADF;
- }
#ifdef _THREAD_SAFE
- if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0) {
- return ret;
- }
+ if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0)
+ return (ret);
#endif
+
+ saved_errno = errno;
errno = 0;
dp = readdir(dirp);
- if (dp == NULL && errno != 0) {
+ if (errno != 0) {
+ if (dp == NULL) {
#ifdef _THREAD_SAFE
- _FD_UNLOCK(dirp->dd_fd, FD_READ);
+ _FD_UNLOCK(dirp->dd_fd, FD_READ);
#endif
- return errno;
- }
- if (dp != NULL) {
+ return (errno);
+ }
+ } else
+ errno = saved_errno;
+
+ if (dp != NULL)
memcpy(entry, dp, sizeof *entry);
- }
+
#ifdef _THREAD_SAFE
_FD_UNLOCK(dirp->dd_fd, FD_READ);
#endif
- if (dp != NULL) {
+
+ if (dp != NULL)
*result = entry;
- } else {
+ else
*result = NULL;
- }
- return 0;
+
+ return (0);
}