diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
| commit | 69aec538b456402170dc723af417ba5c05389c32 (patch) | |
| tree | e6f34c543f17c6392447ea337b2e2868212424d1 /readsubdir.c | |
| download | qmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2 qmail-69aec538b456402170dc723af417ba5c05389c32.zip | |
qmail 1.03 import
Diffstat (limited to 'readsubdir.c')
| -rw-r--r-- | readsubdir.c | 49 |
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 | |||
| 7 | void readsubdir_init(rs,name,pause) | ||
| 8 | readsubdir *rs; | ||
| 9 | char *name; | ||
| 10 | void (*pause)(); | ||
| 11 | { | ||
| 12 | rs->name = name; | ||
| 13 | rs->pause = pause; | ||
| 14 | rs->dir = 0; | ||
| 15 | rs->pos = 0; | ||
| 16 | } | ||
| 17 | |||
| 18 | static char namepos[FMT_ULONG + 4 + READSUBDIR_NAMELEN]; | ||
| 19 | |||
| 20 | int readsubdir_next(rs,id) | ||
| 21 | readsubdir *rs; | ||
| 22 | unsigned 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 | } | ||
