summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/readdir.c
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>1999-11-29 19:12:50 +0000
committeralfred <alfred@FreeBSD.org>1999-11-29 19:12:50 +0000
commitf7d7085dbeec7f40c137f190df9dc78b149e8700 (patch)
tree24ad09a86004895427458929f86e421378a1ee5c /lib/libc/gen/readdir.c
parent903b2c868c14cd85dd3b2e2675969b9cb17f94ea (diff)
downloadFreeBSD-src-f7d7085dbeec7f40c137f190df9dc78b149e8700.zip
FreeBSD-src-f7d7085dbeec7f40c137f190df9dc78b149e8700.tar.gz
style fixes, remove extra braces.
readdir_r is not POSIX according to POSIX_SOURCE, bruce says: > readdir_r() is in the _POSIX_SOURCE section, but is not a POSIX.1-1990 > function. It's POSIX.1-1996 so it should be under a different feature > test which we don't support yet. make sure errno is saved so that its contents are cleared unless necessary. Submitted by: bde
Diffstat (limited to 'lib/libc/gen/readdir.c')
-rw-r--r--lib/libc/gen/readdir.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c
index 9b8c175..2e91a9a 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);
}
OpenPOWER on IntegriCloud