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
This commit is contained in:
parent
6c48b6cf75
commit
8b6c02f328
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53892
@ -31,9 +31,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* @(#)dirent.h 8.2 (Berkeley) 7/28/94
|
* @(#)dirent.h 8.2 (Berkeley) 7/28/94
|
||||||
*
|
|
||||||
* $FreeBSD$
|
* $FreeBSD$
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _DIRENT_H_
|
#ifndef _DIRENT_H_
|
||||||
@ -97,8 +95,8 @@ int scandir __P((const char *, struct dirent ***,
|
|||||||
int (*)(struct dirent *), int (*)(const void *, const void *)));
|
int (*)(struct dirent *), int (*)(const void *, const void *)));
|
||||||
int alphasort __P((const void *, const void *));
|
int alphasort __P((const void *, const void *));
|
||||||
int getdirentries __P((int, char *, int, long *));
|
int getdirentries __P((int, char *, int, long *));
|
||||||
#endif /* not POSIX */
|
|
||||||
int readdir_r __P((DIR *, struct dirent *, struct dirent **));
|
int readdir_r __P((DIR *, struct dirent *, struct dirent **));
|
||||||
|
#endif /* not POSIX */
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif /* !KERNEL */
|
#endif /* !KERNEL */
|
||||||
|
@ -89,34 +89,37 @@ readdir_r(dirp, entry, result)
|
|||||||
struct dirent **result;
|
struct dirent **result;
|
||||||
{
|
{
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
int ret;
|
int ret, saved_errno;
|
||||||
|
|
||||||
if (dirp->dd_fd < 0) {
|
|
||||||
return EBADF;
|
|
||||||
}
|
|
||||||
#ifdef _THREAD_SAFE
|
#ifdef _THREAD_SAFE
|
||||||
if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0) {
|
if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0)
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
saved_errno = errno;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
dp = readdir(dirp);
|
dp = readdir(dirp);
|
||||||
if (dp == NULL && errno != 0) {
|
if (errno != 0) {
|
||||||
|
if (dp == NULL) {
|
||||||
#ifdef _THREAD_SAFE
|
#ifdef _THREAD_SAFE
|
||||||
_FD_UNLOCK(dirp->dd_fd, FD_READ);
|
_FD_UNLOCK(dirp->dd_fd, FD_READ);
|
||||||
#endif
|
#endif
|
||||||
return errno;
|
return (errno);
|
||||||
}
|
}
|
||||||
if (dp != NULL) {
|
} else
|
||||||
|
errno = saved_errno;
|
||||||
|
|
||||||
|
if (dp != NULL)
|
||||||
memcpy(entry, dp, sizeof *entry);
|
memcpy(entry, dp, sizeof *entry);
|
||||||
}
|
|
||||||
#ifdef _THREAD_SAFE
|
#ifdef _THREAD_SAFE
|
||||||
_FD_UNLOCK(dirp->dd_fd, FD_READ);
|
_FD_UNLOCK(dirp->dd_fd, FD_READ);
|
||||||
#endif
|
#endif
|
||||||
if (dp != NULL) {
|
|
||||||
|
if (dp != NULL)
|
||||||
*result = entry;
|
*result = entry;
|
||||||
} else {
|
else
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
}
|
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user