From 39e65e0113e188e4177077407d337bb3a1ac1853 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 5 Jun 2002 20:58:59 +0000 Subject: 2002-06-05 Jeff Johnston * libc/include/string.h[__linux__]: Add strsignal prototype. * libc/include/sys/lock.h: New file with default locking support. * libc/include/sys/reent.h: Add signal buffer support for strsignal and psignal. * libc/posix/Makefile.am: Add support for readdir_r.c. * libc/posix/Makefile.in: Regenerated. * libc/posix/closedir.c: Add locking support and hash table cleanup. * libc/posix/opendir.c: Add lock support. * libc/posix/readdir.c: Ditto. * libc/posix/rewinddir.c: Ditto. * libc/posix/scandir.c: Ditto. * libc/posix/seekdir.c: Ditto. * libc/posix/telldir.c: Ditto plus add _cleanupdir routine to clean up leftover hash table entries. * libc/posix/readdir_r.c: New file. * libc/sys/linux/Makefile.am: Add psignal.c and strsignal.c support. * libc/sys/linux/Makefile.in: Regenerated. * libc/sys/linux/sys/dirent.h: Add dd_lock to DIR structure. * libc/sys/linux/sys/signal.h: Add psignal prototype. * libc/sys/linux/psignal.c: New file. * libc/sys/linux/strsignal.c: Ditto. --- newlib/libc/posix/scandir.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'newlib/libc/posix/scandir.c') diff --git a/newlib/libc/posix/scandir.c b/newlib/libc/posix/scandir.c index 6acaff739..bcbe57fbd 100644 --- a/newlib/libc/posix/scandir.c +++ b/newlib/libc/posix/scandir.c @@ -49,6 +49,7 @@ static char sccsid[] = "@(#)scandir.c 5.10 (Berkeley) 2/23/91"; #include #include #include +#include /* * The DIRSIZ macro gives the minimum record length which will hold @@ -84,8 +85,15 @@ scandir(dirname, namelist, select, dcomp) if ((dirp = opendir(dirname)) == NULL) return(-1); - if (fstat(dirp->dd_fd, &stb) < 0) +#ifdef HAVE_DD_LOCK + __lock_acquire_recursive(dirp->dd_lock); +#endif + if (fstat(dirp->dd_fd, &stb) < 0) { +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); +#endif return(-1); + } /* * estimate the array size by taking the size of the directory file @@ -93,8 +101,12 @@ scandir(dirname, namelist, select, dcomp) */ arraysz = (stb.st_size / 24); names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); - if (names == NULL) + if (names == NULL) { +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); +#endif return(-1); + } nitems = 0; while ((d = readdir(dirp)) != NULL) { @@ -104,8 +116,12 @@ scandir(dirname, namelist, select, dcomp) * Make a minimum size copy of the data */ p = (struct dirent *)malloc(DIRSIZ(d)); - if (p == NULL) + if (p == NULL) { +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); +#endif return(-1); + } p->d_ino = d->d_ino; p->d_reclen = d->d_reclen; #ifdef _DIRENT_HAVE_D_NAMLEN @@ -119,13 +135,21 @@ scandir(dirname, namelist, select, dcomp) * realloc the maximum size. */ if (++nitems >= arraysz) { - if (fstat(dirp->dd_fd, &stb) < 0) + if (fstat(dirp->dd_fd, &stb) < 0) { +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); +#endif return(-1); /* just might have grown */ + } arraysz = stb.st_size / 12; names = (struct dirent **)realloc((char *)names, arraysz * sizeof(struct dirent *)); - if (names == NULL) + if (names == NULL) { +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); +#endif return(-1); + } } names[nitems-1] = p; } @@ -133,6 +157,9 @@ scandir(dirname, namelist, select, dcomp) if (nitems && dcomp != NULL) qsort(names, nitems, sizeof(struct dirent *), dcomp); *namelist = names; +#ifdef HAVE_DD_LOCK + __lock_release_recursive(dirp->dd_lock); +#endif return(nitems); } -- cgit v1.2.3