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)
8 * This file can be redistributed under the terms of the GNU Library General
19 int iterate_on_dir (const char * dir_name,
20 int (*func) (const char *, struct dirent *, void *),
24 #if HAVE_DIRENT_NAMELEN
25 /* Declare DE_BUF with some extra room for the name. */
26 char de_buf[sizeof (struct dirent) + 32];
27 struct dirent *de = (struct dirent *)&de_buf;
29 struct dirent de_buf, *de = &de_buf;
33 dir = opendir (dir_name);
36 while ((dep = readdir (dir)))
38 #if HAVE_DIRENT_NAMELEN
39 /* See if there's enough room for this entry in DE, and grow if
41 if (de_len < dep->d_reclen)
43 de_len = dep->d_reclen + 32;
45 (de == (struct dirent *)&de_buf
47 : realloc (de, de_len));
54 memcpy (de, dep, dep->d_reclen);
58 (*func) (dir_name, de, private);
60 #if HAVE_DIRENT_NAMELEN
61 if (de != (struct dirent *)&de_buf)