diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | manual/filesys.texi | 3 | ||||
-rw-r--r-- | sysdeps/unix/readdir_r.c | 12 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/readdir64_r.c | 12 |
4 files changed, 25 insertions, 8 deletions
@@ -1,3 +1,9 @@ +1998-03-10 19:43 Matthias Urlichs <urlichs@noris.de> + + * sysdeps/unix/readdir_r.c: zero out *result on EOF. + * sysdeps/unix/sysv/linux/readdir64_r.c: Likewise. + * manual/filesys/texi: document this. + 1998-03-10 10:49 Ulrich Drepper <drepper@cygnus.com> * manual/filesys.texi: Document the change below. diff --git a/manual/filesys.texi b/manual/filesys.texi index 3b125cd..951ae79 100644 --- a/manual/filesys.texi +++ b/manual/filesys.texi @@ -354,6 +354,9 @@ successfully. In this case a pointer to the result is returned in the function returns a value indicating the error (as described for @code{readdir}). +If there are no more directory entries, @code{readdir_r}'s return value is +@code{0}, and *@var{result} is set to @code{NULL}. + @strong{Portability Note:} On some systems, @code{readdir_r} may not return a terminated string as the file name even if no @code{d_reclen} element is available in @code{struct dirent} and the file name as the diff --git a/sysdeps/unix/readdir_r.c b/sysdeps/unix/readdir_r.c index 6d70233..15a4c37 100644 --- a/sysdeps/unix/readdir_r.c +++ b/sysdeps/unix/readdir_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -59,7 +59,8 @@ __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result) if (bytes <= 0) { dp = NULL; - reclen = 0; + /* Reclen != 0 signals that an error occurred. */ + reclen = bytes != 0; break; } dirp->size = (size_t) bytes; @@ -93,13 +94,16 @@ __readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result) #endif /* Skip deleted files. */ - } while (dp->d_ino == 0); + } + while (dp->d_ino == 0); if (dp != NULL) *result = memcpy (entry, dp, reclen); + else + *result = NULL; __libc_lock_unlock (dirp->lock); - return dp != NULL ? 0 : errno; + return dp != NULL ? 0 : reclen ? errno : 0; } weak_alias (__readdir_r, readdir_r) diff --git a/sysdeps/unix/sysv/linux/readdir64_r.c b/sysdeps/unix/sysv/linux/readdir64_r.c index 57ae4c7..5e711c4 100644 --- a/sysdeps/unix/sysv/linux/readdir64_r.c +++ b/sysdeps/unix/sysv/linux/readdir64_r.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997 Free Software Foundation, Inc. +/* Copyright (C) 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -62,7 +62,8 @@ readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result) if (bytes <= 0) { dp = NULL; - reclen = 0; + /* Reclen != 0 signals that an error occurred. */ + reclen = bytes != 0; break; } dirp->size = (size_t) bytes; @@ -96,12 +97,15 @@ readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result) #endif /* Skip deleted files. */ - } while (dp->d_ino == 0); + } + while (dp->d_ino == 0); if (dp != NULL) *result = memcpy (entry, dp, reclen); + else + *result = NULL; __libc_lock_unlock (dirp->lock); - return dp != NULL ? 0 : errno; + return dp != NULL ? 0 : reclen ? errno : 0; } |