#include #include #include #include #include #include #include #include #include "mailbox.h" int get_dir_entries (char * dirname, struct entry *list[], int listlen) { DIR * d; struct dirent * ent; struct stat statbuf; char strbuf[1000]; int nentry; d = opendir (dirname); if (!d) return 0; nentry = 0; while ((ent = readdir (d))) { sprintf (strbuf, "%s/%s", dirname, ent->d_name); if (stat (strbuf, &statbuf) < 0) return -1; if ((statbuf.st_mode & S_IFMT) != S_IFREG) continue; if (nentry >= listlen) { errno = EOVERFLOW; return -1; } list[nentry] = malloc (sizeof (struct entry)); list[nentry]->nam = strdup (ent->d_name); list[nentry]->del = 0; if (strlen (dirname) + strlen (list[nentry]->nam) +2 >= 1000) { errno = ENAMETOOLONG; return -1; } list[nentry]->size = statbuf.st_size; nentry++; } closedir (d); return nentry; }