diff options
Diffstat (limited to 'newlib/libc/posix/closedir.c')
-rw-r--r-- | newlib/libc/posix/closedir.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/newlib/libc/posix/closedir.c b/newlib/libc/posix/closedir.c index 4ad6e4c97..57222f947 100644 --- a/newlib/libc/posix/closedir.c +++ b/newlib/libc/posix/closedir.c @@ -41,6 +41,9 @@ static char sccsid[] = "@(#)closedir.c 5.9 (Berkeley) 2/23/91"; #include <dirent.h> #include <stdlib.h> #include <unistd.h> +#include <sys/lock.h> + +extern void _cleanupdir (DIR *dirp); /* * close a directory. @@ -49,14 +52,26 @@ int closedir(dirp) register DIR *dirp; { - int fd; + int fd, rc; +#ifdef HAVE_DD_LOCK + __lock_acquire_recursive(dirp->dd_lock); +#endif + rc = 0; fd = dirp->dd_fd; - dirp->dd_fd = -1; - dirp->dd_loc = 0; - (void)free((void *)dirp->dd_buf); - (void)free((void *)dirp); - return(close(fd)); + if (fd != -1) { + dirp->dd_fd = -1; + dirp->dd_loc = 0; + (void)free((void *)dirp->dd_buf); + (void)free((void *)dirp); + rc = close(fd); + _cleanupdir(dirp); + } +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); + __lock_close_recursive(dirp->dd_lock); +#endif + return rc; } #endif /* ! HAVE_OPENDIR */ |