source: MondoRescue/branches/2.2.2/mindi-busybox/e2fsprogs/e2p/iod.c@ 1247

Last change on this file since 1247 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 1.1 KB
Line 
1/*
2 * iod.c - Iterate a function on each entry of a directory
3 *
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)
7 *
8 * This file can be redistributed under the terms of the GNU Library General
9 * Public License
10 */
11
12/*
13 * History:
14 * 93/10/30 - Creation
15 */
16
17#include "e2p.h"
18#include <unistd.h>
19#include <stdlib.h>
20#include <string.h>
21
22int iterate_on_dir (const char * dir_name,
23 int (*func) (const char *, struct dirent *, void *),
24 void * private)
25{
26 DIR * dir;
27 struct dirent *de, *dep;
28 int max_len, len;
29
30 max_len = PATH_MAX + sizeof(struct dirent);
31 de = (struct dirent *)xmalloc(max_len+1);
32 memset(de, 0, max_len+1);
33
34 dir = opendir (dir_name);
35 if (dir == NULL) {
36 free(de);
37 return -1;
38 }
39 while ((dep = readdir (dir))) {
40 len = sizeof(struct dirent);
41 if (len < dep->d_reclen)
42 len = dep->d_reclen;
43 if (len > max_len)
44 len = max_len;
45 memcpy(de, dep, len);
46 (*func) (dir_name, de, private);
47 }
48 free(de);
49 closedir(dir);
50 return 0;
51}
Note: See TracBrowser for help on using the repository browser.