1 /* vi: set sw=4 ts=4: */
3 * iod.c - Iterate a function on each entry of a directory
5 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
6 * Laboratoire MASI, Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
9 * This file can be redistributed under the terms of the GNU Library General
23 int iterate_on_dir (const char * dir_name,
24 int (*func) (const char *, struct dirent *, void *),
28 struct dirent *de, *dep;
31 max_len = PATH_MAX + sizeof(struct dirent);
32 de = (struct dirent *)xmalloc(max_len+1);
33 memset(de, 0, max_len+1);
35 dir = opendir (dir_name);
40 while ((dep = readdir (dir))) {
41 len = sizeof(struct dirent);
42 if (len < dep->d_reclen)
47 (*func) (dir_name, de, private);