File: readsubdir.c

package info (click to toggle)
qmail 1.03-44
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 4,244 kB
  • ctags: 2,091
  • sloc: ansic: 16,309; makefile: 2,446; sh: 772; perl: 509
file content (49 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "readsubdir.h"
#include "fmt.h"
#include "scan.h"
#include "str.h"
#include "auto_split.h"

void readsubdir_init(rs,name,pause)
readsubdir *rs;
char *name;
void (*pause)();
{
 rs->name = name;
 rs->pause = pause;
 rs->dir = 0;
 rs->pos = 0;
}

static char namepos[FMT_ULONG + 4 + READSUBDIR_NAMELEN];

int readsubdir_next(rs,id)
readsubdir *rs;
unsigned long *id;
{
 direntry *d;
 unsigned int len;

 if (!rs->dir)
  {
   if (rs->pos >= auto_split) return 0;
   if (str_len(rs->name) > READSUBDIR_NAMELEN) { rs->pos++; return -1; }
   len = 0;
   len += fmt_str(namepos + len,rs->name);
   namepos[len++] = '/';
   len += fmt_ulong(namepos + len,(unsigned long) rs->pos);
   namepos[len] = 0;
   while (!(rs->dir = opendir(namepos))) rs->pause(namepos);
   rs->pos++;
   return -1;
  }

 d = readdir(rs->dir);
 if (!d) { closedir(rs->dir); rs->dir = 0; return -1; }

 if (str_equal(d->d_name,".")) return -1;
 if (str_equal(d->d_name,"..")) return -1;
 len = scan_ulong(d->d_name,id);
 if (!len || d->d_name[len]) return -2;
 return 1;
}