summaryrefslogtreecommitdiffstats
path: root/readsubdir.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-02-04 00:08:53 +0100
committermanuel <manuel@mausz.at>2013-02-04 00:08:53 +0100
commit69aec538b456402170dc723af417ba5c05389c32 (patch)
treee6f34c543f17c6392447ea337b2e2868212424d1 /readsubdir.c
downloadqmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz
qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2
qmail-69aec538b456402170dc723af417ba5c05389c32.zip
qmail 1.03 import
Diffstat (limited to 'readsubdir.c')
-rw-r--r--readsubdir.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/readsubdir.c b/readsubdir.c
new file mode 100644
index 0000000..81aa241
--- /dev/null
+++ b/readsubdir.c
@@ -0,0 +1,49 @@
1#include "readsubdir.h"
2#include "fmt.h"
3#include "scan.h"
4#include "str.h"
5#include "auto_split.h"
6
7void readsubdir_init(rs,name,pause)
8readsubdir *rs;
9char *name;
10void (*pause)();
11{
12 rs->name = name;
13 rs->pause = pause;
14 rs->dir = 0;
15 rs->pos = 0;
16}
17
18static char namepos[FMT_ULONG + 4 + READSUBDIR_NAMELEN];
19
20int readsubdir_next(rs,id)
21readsubdir *rs;
22unsigned long *id;
23{
24 direntry *d;
25 unsigned int len;
26
27 if (!rs->dir)
28 {
29 if (rs->pos >= auto_split) return 0;
30 if (str_len(rs->name) > READSUBDIR_NAMELEN) { rs->pos++; return -1; }
31 len = 0;
32 len += fmt_str(namepos + len,rs->name);
33 namepos[len++] = '/';
34 len += fmt_ulong(namepos + len,(unsigned long) rs->pos);
35 namepos[len] = 0;
36 while (!(rs->dir = opendir(namepos))) rs->pause(namepos);
37 rs->pos++;
38 return -1;
39 }
40
41 d = readdir(rs->dir);
42 if (!d) { closedir(rs->dir); rs->dir = 0; return -1; }
43
44 if (str_equal(d->d_name,".")) return -1;
45 if (str_equal(d->d_name,"..")) return -1;
46 len = scan_ulong(d->d_name,id);
47 if (!len || d->d_name[len]) return -2;
48 return 1;
49}