diff options
author | Raja R Harinath <harinath@cs.umn.edu> | 1998-04-08 23:09:26 +0000 |
---|---|---|
committer | Raja R Harinath <harinath@src.gnome.org> | 1998-04-08 23:09:26 +0000 |
commit | cfa9ba9476e03dc29b5a402739b833a8d2a185ec (patch) | |
tree | b76753230073dde346d811087daf3a1a9de18746 | |
parent | 5dc0bdba5af0c8fcdc8ea859880e158fcbb70fab (diff) | |
download | gnome-common-cfa9ba9476e03dc29b5a402739b833a8d2a185ec.tar.gz |
Import from GNU libc. Remove assumptions that this file is compiled inside
* scandir.c: Import from GNU libc.
Remove assumptions that this file is compiled inside GLIBC.
Here are the ChangeLog entries when I imported it originally into
`gwp':
1998-02-08 Raja R Harinath <harinath@cs.umn.edu>
* scandir.c (scandir): Revert change of `1998-02-07'.
Don't use d_reclen, but fix the expression used to
figure out the length.
1998-02-07 Raja R Harinath <harinath@cs.umn.edu>
* scandir.c (scandir): Use `d_reclen' field to get length
of record.
1998-02-06 Raja R Harinath <harinath@cs.umn.edu>
* scandir.c: New file. Replacement function copied from
glibc, edited to not step on implementation namespace.
svn path=/trunk/; revision=186
-rw-r--r-- | support/ChangeLog | 20 | ||||
-rw-r--r-- | support/scandir.c | 48 |
2 files changed, 58 insertions, 10 deletions
diff --git a/support/ChangeLog b/support/ChangeLog index 6ce0c4b..e6b45b9 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,23 @@ +1998-04-08 Raja R Harinath <harinath@cs.umn.edu> + + * scandir.c: Import from GNU libc. + Remove assumptions that this file is compiled inside GLIBC. + Here are the ChangeLog entries when I imported it originally into + `gwp': + + 1998-02-08 Raja R Harinath <harinath@cs.umn.edu> + * scandir.c (scandir): Revert change of `1998-02-07'. + Don't use d_reclen, but fix the expression used to + figure out the length. + + 1998-02-07 Raja R Harinath <harinath@cs.umn.edu> + * scandir.c (scandir): Use `d_reclen' field to get length + of record. + + 1998-02-06 Raja R Harinath <harinath@cs.umn.edu> + * scandir.c: New file. Replacement function copied from + glibc, edited to not step on implementation namespace. + 1998-03-28 Raja R Harinath <harinath@cs.umn.edu> * vasprintf.c (int_vasprintf): Imported from GNU libit-0.4. diff --git a/support/scandir.c b/support/scandir.c index 58a2c75..39cb6dd 100644 --- a/support/scandir.c +++ b/support/scandir.c @@ -16,17 +16,45 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <dirent.h> +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif #include <stdlib.h> #include <string.h> #include <errno.h> +#if HAVE_DIRENT_H +# include <dirent.h> +# define NAMLEN(dirent) strlen((dirent)->d_name) +#else +# define dirent direct +# define NAMLEN(dirent) (dirent)->d_namlen +# if HAVE_SYS_NDIR_H +# include <sys/ndir.h> +# endif +# if HAVE_SYS_DIR_H +# include <sys/dir.h> +# endif +# if HAVE_NDIR_H +# include <ndir.h> +# endif +#endif + +#undef PARAMS +#if defined (__GNUC__) || __STDC__ +# define PARAMS(args) args +#else +# define PARAMS(args) () +#endif + +#define set_errno(e) (errno = (e)) + int scandir (dir, namelist, select, cmp) const char *dir; struct dirent ***namelist; - int (*select) __P ((struct dirent *)); - int (*cmp) __P ((const void *, const void *)); + int (*select) PARAMS ((struct dirent *)); + int (*cmp) PARAMS ((const void *, const void *)); { DIR *dp = opendir (dir); struct dirent **v = NULL; @@ -38,16 +66,16 @@ scandir (dir, namelist, select, cmp) return -1; save = errno; - __set_errno (0); + set_errno (0); i = 0; - while ((d = __readdir (dp)) != NULL) + while ((d = readdir (dp)) != NULL) if (select == NULL || (*select) (d)) { size_t dsize; /* Ignore errors from select or readdir */ - __set_errno (0); + set_errno (0); if (i == vsize) { @@ -60,13 +88,13 @@ scandir (dir, namelist, select, cmp) if (new == NULL) { lose: - __set_errno (ENOMEM); + set_errno (ENOMEM); break; } v = new; } - dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d; + dsize = &d->d_name[1 + NAMLEN (d)] - (char *) d; v[i] = (struct dirent *) malloc (dsize); if (v[i] == NULL) goto lose; @@ -81,12 +109,12 @@ scandir (dir, namelist, select, cmp) while (i > 0) free (v[--i]); free (v); - __set_errno (save); + set_errno (save); return -1; } (void) closedir (dp); - __set_errno (save); + set_errno (save); /* Sort the list if we have a comparison function to sort with. */ if (cmp != NULL) |