s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
readsubdir.c
Go to the documentation of this file.
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(readsubdir *rs, char *name, void (*pause)())
8{
9 rs->name = name;
10 rs->pause = pause;
11 rs->dir = 0;
12 rs->pos = 0;
13}
14
15static char namepos[FMT_ULONG + 4 + READSUBDIR_NAMELEN];
16
17int readsubdir_next(readsubdir *rs, unsigned long *id)
18{
19 direntry *d;
20 unsigned int len;
21
22 if (!rs->dir) {
23 if (rs->pos >= auto_split) return 0;
24 if (str_len(rs->name) > READSUBDIR_NAMELEN) { rs->pos++; return -1; }
25 len = 0;
26 len += fmt_str(namepos + len,rs->name);
27 namepos[len++] = '/';
28 len += fmt_ulong(namepos + len,(unsigned long) rs->pos);
29 namepos[len] = 0;
30 while (!(rs->dir = opendir(namepos))) rs->pause(namepos);
31 rs->pos++;
32 return -1;
33 }
34
35 d = readdir(rs->dir);
36 if (!d) { closedir(rs->dir); rs->dir = 0; return -1; }
37
38 if (str_equal(d->d_name,".")) return -1;
39 if (str_equal(d->d_name,"..")) return -1;
40 len = scan_ulong(d->d_name,id);
41 if (!len || d->d_name[len]) return -2;
42
43 return 1;
44}
int auto_split
readsubdir rs
Definition: qmail-qread.c:17
struct del * d[CHANNELS]
Definition: qmail-send.c:720
int readsubdir_next()
#define READSUBDIR_NAMELEN
Definition: readsubdir.h:18
void readsubdir_init()
void(* pause)()
Definition: readsubdir.h:11
char * name
Definition: readsubdir.h:10
DIR * dir
Definition: readsubdir.h:8