#include #include #include #include #include #if 0 MYGLOBDATA *myglob (char *dir, char *pattern, int allfiles, int sortforward) { MYGLOBDATA *g = NULL; int error = 0; DIR *globdir = NULL; int count; struct dirent *filedat; error = chdir(dir); if (!error) error = ((globdir = opendir(".")) == NULL); if (!error) { g = mallocwrapper(sizeof(MYGLOBDATA)); g->namecount = 0; g->name = NULL; g->stat_buf = NULL; g->blocks = 0; while((filedat = readdir(globdir)) != NULL) { if ((filedat->d_name[0] != '.') || (allfiles)) { if (my_fnmatch(pattern, filedat->d_name, 0) == 0) { (g->namecount)++; reallocwrapper(sizeof(char **) * g->namecount, (void *)&(g->name)); g->name[g->namecount - 1] = strdupwrapper(filedat->d_name); } } } reallocwrapper(sizeof(char **) * (g->namecount + 1), (void *)&(g->name)); g->name[g->namecount] = NULL; if (g->namecount > 0) { qsortarray(g->name, 0, g->namecount-1); g->stat_buf = mallocwrapper(sizeof(struct stat) * (g->namecount)); for(count = 0; count < g->namecount; count++) { if (lstat(g->name[count], g->stat_buf + count) == -1) { printf("stat error\n"); memset(g->stat_buf + count, 0, sizeof(struct stat)); } else g->blocks += g->stat_buf[count].st_blocks / 2; } } } if (globdir) closedir(globdir); return(g); } #endif static int check(char *s, int n, char v) { int i; for (i = 0; i < n; i++) { if (s[i] != v) { printf("bork!\n"); return 1; } } return 0; } int main(int ac, char **av) { int error = 0; DIR *globdir = NULL; int count; struct dirent *filedat; struct stat stbuf[3]; char *t1 = (stbuf); char *t3 = (stbuf + 2); if ((globdir = opendir(".")) == NULL) return 1; memset(stbuf, 0x88, sizeof(stbuf)); while ((filedat = readdir(globdir)) != NULL) { printf("%s\n", filedat->d_name); if (lstat(filedat->d_name, &stbuf[1]) == -1) { printf("stat error\n"); continue; } check(t1, sizeof(stbuf[0]), 0x88); check(t3, sizeof(stbuf[2]), 0x88); } closedir(globdir); return 0; }