From e7efcb5302ff3b4faef7cf619f51a4b4a509f09a Mon Sep 17 00:00:00 2001 From: alfred Date: Sun, 28 Nov 1999 05:38:13 +0000 Subject: add pthread_cancel, obtained from OpenBSD. eischen (Daniel Eischen) added wrappers to protect against cancled threads orphaning internal resources. the cancelability code is still a bit fuzzy but works for test programs of my own, OpenBSD's and some examples from ORA's books. add readdir_r to both libc and libc_r add some 'const' attributes to function parameters Reviewed by: eischen, jasone --- lib/libc/gen/readdir.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib/libc') diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c index ab3a404..74246b9 100644 --- a/lib/libc/gen/readdir.c +++ b/lib/libc/gen/readdir.c @@ -29,6 +29,9 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $FreeBSD$ + * */ #if defined(LIBC_SCCS) && !defined(lint) @@ -37,6 +40,11 @@ static char sccsid[] = "@(#)readdir.c 8.3 (Berkeley) 9/29/94"; #include #include +#include +#ifdef _THREAD_SAFE +#include +#include "pthread_private.h" +#endif _THREAD_SAFE /* * get next entry in a directory. @@ -73,3 +81,39 @@ readdir(dirp) return (dp); } } + +int +readdir_r(dirp, entry, result) + DIR *dirp; + struct dirent *entry; + struct dirent **result; +{ + struct dirent *dp; + int ret; + + if (dirp->dd_fd < 0) { + return EBADF; + } +#ifdef _THREAD_SAFE + if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0) + return ret; +#endif + errno = 0; + dp = readdir(dirp); + if (dp == NULL && errno != 0) { +#ifdef _THREAD_SAFE + _FD_UNLOCK(dirp->dd_fd, FD_READ); +#endif + return errno; + } + if (dp != NULL) + memcpy(entry, dp, sizeof *entry); +#ifdef _THREAD_SAFE + _FD_UNLOCK(dirp->dd_fd, FD_READ); +#endif + if (dp != NULL) + *result = entry; + else + *result = NULL; + return 0; +} -- cgit v1.1