Example #1
0
/* count the number of mails in a root mail directory */
int countmails(const char *dir) {
        DIR *dp;
        struct dirent *ep;
        int ret = 0;

        /* open directory */
        dp = opendir(dir);
        if (dp == NULL)
                return -1;

        /* iterate through directory */
        while ((ep = readdir(dp)) != NULL) {
                if (*(ep->d_name) == '.')
                        continue;
                char *path = calloc(256, sizeof(char));
                snprintf(path, 255, "%s/%s/new", dir, ep->d_name);
                ret += countdir(path);
                free(path);
        }

        return ret;
}
Example #2
0
static int count(int u,int v) {
	int seen=1,d,dummy;
	for(d=0;d<4;d++) seen+=countdir(u,v,d,0,&dummy);
	return seen;
}