/* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * * $Id$ * */ #include #include #include #include #include #include #include #include #include int barf[256]; int CheckMode = 0; int pstrcmp(const void *pp, const void *qq) { return strcmp(*(char **)pp,*(char **)qq); } int Do(char *path) { DIR *d; struct dirent *de; struct stat st; int ret=0; u_char buf[BUFSIZ]; u_char data[BUFSIZ],*q; int bufp; MD5_CTX ctx; int fd,i,j,k,l,npde,nde=0; char **pde, md5[33]; npde = 1; pde = malloc(sizeof *pde * (npde+1)); d = opendir(path); if(!d) { perror(path); return 2; } if(!strcmp(path,".")) { *buf = 0; } else { strcpy(buf,path); if(buf[strlen(buf)-1] != '/') strcat(buf,"/"); } bufp = strlen(buf); while((de=readdir(d))) { if(!strcmp(de->d_name,".")) continue; if(!strcmp(de->d_name,"..")) continue; if(nde >= npde) { npde *= 2; pde = realloc(pde,sizeof *pde * (npde+1)); } strcpy(buf+bufp,de->d_name); if(stat(buf,&st)) { ret |= 1; continue; } pde[nde] = malloc(strlen(buf+bufp)+1); strcpy(pde[nde++],buf+bufp); } closedir(d); if(!nde) return 0; qsort(pde,nde,sizeof *pde, pstrcmp); for(k=0;k 1 && !strcmp(argv[1],"-c")) { CheckMode=1; argc--; argv++; } /* * First argument, if any, is where to do the work. */ if (argc > 1) { if(chdir(argv[1])) { perror(argv[1]); return 2; } argc--; argv++; } /* * Scan the directories recursively. */ if (argc > 1) { while (argc > 1) { i = Do(argv[1]); argc--; argv++; if (i) return i; } return i; } else return Do("."); }