2 * iod.c - Iterate a function on each entry of a directory
4 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
9 * This file may be redistributed under the terms of the GNU Library
10 * General Public License, version 2.
26 int iterate_on_dir (const char * dir_name,
27 int (*func) (const char *, struct dirent *, void *),
31 struct dirent *de, *dep;
32 int max_len = -1, len, ret = 0;
34 #if HAVE_PATHCONF && defined(_PC_NAME_MAX)
35 max_len = pathconf(dir_name, _PC_NAME_MAX);
38 #ifdef _POSIX_NAME_MAX
39 max_len = _POSIX_NAME_MAX;
46 #endif /* _POSIX_NAME_MAX */
48 max_len += sizeof(struct dirent);
50 de = malloc(max_len+1);
53 memset(de, 0, max_len+1);
55 dir = opendir (dir_name);
60 while ((dep = readdir (dir))) {
61 #ifdef HAVE_RECLEN_DIRENT
66 len = sizeof(struct dirent);
69 if ((*func)(dir_name, de, private))