summaryrefslogtreecommitdiff
path: root/e2fsprogs/old_e2fsprogs/e2p/iod.c
diff options
context:
space:
mode:
authorDenis Vlasenko2006-12-26 01:30:59 +0000
committerDenis Vlasenko2006-12-26 01:30:59 +0000
commitc4f623ef2a7980a63de7c9f1d539a656b83f10e7 (patch)
treea294e28b0112052cb9d58b403554b3390e76f50c /e2fsprogs/old_e2fsprogs/e2p/iod.c
parent64c54025842f205ad722675105b88044a5b6845a (diff)
downloadbusybox-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.zip
busybox-c4f623ef2a7980a63de7c9f1d539a656b83f10e7.tar.gz
put small subset of e2fsprogs back in the tree:
lsattr, chattr, fsck. Old e2fsprogs tree is in e2fsprogs/old_e2fsprogs/*.
Diffstat (limited to 'e2fsprogs/old_e2fsprogs/e2p/iod.c')
-rw-r--r--e2fsprogs/old_e2fsprogs/e2p/iod.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/e2fsprogs/old_e2fsprogs/e2p/iod.c b/e2fsprogs/old_e2fsprogs/e2p/iod.c
new file mode 100644
index 0000000..23ab8d5
--- /dev/null
+++ b/e2fsprogs/old_e2fsprogs/e2p/iod.c
@@ -0,0 +1,52 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * iod.c - Iterate a function on each entry of a directory
+ *
+ * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
+ * Laboratoire MASI, Institut Blaise Pascal
+ * Universite Pierre et Marie Curie (Paris VI)
+ *
+ * This file can be redistributed under the terms of the GNU Library General
+ * Public License
+ */
+
+/*
+ * History:
+ * 93/10/30 - Creation
+ */
+
+#include "e2p.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+int iterate_on_dir (const char * dir_name,
+ int (*func) (const char *, struct dirent *, void *),
+ void * private)
+{
+ DIR * dir;
+ struct dirent *de, *dep;
+ int max_len, len;
+
+ max_len = PATH_MAX + sizeof(struct dirent);
+ de = xmalloc(max_len+1);
+ memset(de, 0, max_len+1);
+
+ dir = opendir (dir_name);
+ if (dir == NULL) {
+ free(de);
+ return -1;
+ }
+ while ((dep = readdir (dir))) {
+ len = sizeof(struct dirent);
+ if (len < dep->d_reclen)
+ len = dep->d_reclen;
+ if (len > max_len)
+ len = max_len;
+ memcpy(de, dep, len);
+ (*func) (dir_name, de, private);
+ }
+ free(de);
+ closedir(dir);
+ return 0;
+}