From 90341544e5ddea1402a7f188800d2381d07a1602 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 28 Aug 2002 03:26:52 +0000 Subject: [PATCH] * sysdeps/unix/readdir.c: If getdents fails with ENOENT, restore errno and treat it as an EOF return. * sysdeps/unix/readdir_r.c: Likewise. --- ChangeLog | 4 ++++ sysdeps/unix/readdir.c | 9 ++++++++- sysdeps/unix/readdir_r.c | 13 ++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2356fdaae8..8154f91d8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2002-08-27 Roland McGrath + * sysdeps/unix/readdir.c: If getdents fails with ENOENT, restore errno + and treat it as an EOF return. + * sysdeps/unix/readdir_r.c: Likewise. + * sysdeps/gnu/errlist-compat.awk: Include in output. From Alexandre Oliva . * sysdeps/gnu/errlist-compat.c: Regenerated. diff --git a/sysdeps/unix/readdir.c b/sysdeps/unix/readdir.c index dc015d2802..4a0f0890e9 100644 --- a/sysdeps/unix/readdir.c +++ b/sysdeps/unix/readdir.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,92,93,94,95,96,97,99,2000 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,93,94,95,96,97,99,2000,02 + 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 @@ -64,6 +65,12 @@ __READDIR (DIR *dirp) bytes = __GETDENTS (dirp->fd, dirp->data, maxread); if (bytes <= 0) { + /* On some systems getdents fails with ENOENT when the + open directory has been rmdir'd already. POSIX.1 + requires that we treat this condition like normal EOF. */ + if (bytes < 0 && errno == ENOENT) + bytes = 0; + /* Don't modifiy errno when reaching EOF. */ if (bytes == 0) __set_errno (saved_errno); diff --git a/sysdeps/unix/readdir_r.c b/sysdeps/unix/readdir_r.c index f4d7aad0e0..f84709e737 100644 --- a/sysdeps/unix/readdir_r.c +++ b/sysdeps/unix/readdir_r.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,02 + 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 @@ -40,6 +41,7 @@ __READDIR_R (DIR *dirp, DIRENT_TYPE *entry, DIRENT_TYPE **result) { DIRENT_TYPE *dp; size_t reclen; + const int saved_errno = errno; __libc_lock_lock (dirp->lock); @@ -62,6 +64,15 @@ __READDIR_R (DIR *dirp, DIRENT_TYPE *entry, DIRENT_TYPE **result) bytes = __GETDENTS (dirp->fd, dirp->data, maxread); if (bytes <= 0) { + /* On some systems getdents fails with ENOENT when the + open directory has been rmdir'd already. POSIX.1 + requires that we treat this condition like normal EOF. */ + if (bytes < 0 && errno == ENOENT) + { + bytes = 0; + __set_errno (saved_errno); + } + dp = NULL; /* Reclen != 0 signals that an error occurred. */ reclen = bytes != 0; -- 2.43.5