Вроде все ищет и во все подкаталоги залазит, но в конце, после вывода рузультата, появляется сообщение "ошибка сигментирования". Чо не так?
Код: Выделить всё
char s1[255];
char s2[255];
char s4[255];
int z=0;
void *func_thread(void *param)
{
DIR *dp,*pdp;
struct dirent *d;
struct stat file;
int x=0;
dp=opendir((char*)param);
while(d=readdir(dp))
{
char path[255];
strcpy(path,(char*)param);
strcat(path,"/");
strcat(path,d->d_name);
stat(path,&file);
pdp=opendir(path);
if(pdp!=0) { if((strcmp(d->d_name,"..")!=0) && (strcmp(d->d_name,".")!=0)) func_thread(path);}
if((!pdp)&&(file.st_size>atoi(s1))&&(file.st_size<atoi(s2))&&(((file.st_mode&S_IXUSR)!=0)))
{
printf("%u %s %s %d\n",pthread_self(),(char*)param,d->d_name, (int)file.st_size);
FILE *fp;
fp=fopen(s4,"a");
fprintf(fp,"%s %s %d ",(char*)param,d->d_name,(int)file.st_size);
if((file.st_mode & S_IRUSR)!=0) fprintf(fp,"r"); else fprintf(fp,"-");
if((file.st_mode & S_IWUSR)!=0) fprintf(fp,"w"); else fprintf(fp,"-");
if((file.st_mode & S_IXUSR)!=0) fprintf(fp,"x"); else fprintf(fp,"-");
if((file.st_mode & S_IRGRP)!=0) fprintf(fp,"r"); else fprintf(fp,"-");
if((file.st_mode & S_IWGRP)!=0) fprintf(fp,"w"); else fprintf(fp,"-");
if((file.st_mode & S_IXGRP)!=0) fprintf(fp,"x"); else fprintf(fp,"-");
if((file.st_mode & S_IROTH)!=0) fprintf(fp,"r"); else fprintf(fp,"-");
if((file.st_mode & S_IWOTH)!=0) fprintf(fp,"w"); else fprintf(fp,"-");
if((file.st_mode & S_IXOTH)!=0) fprintf(fp,"x"); else fprintf(fp,"-");
fprintf(fp,"\n");
fclose(fp);
x++;
}
}
z--;
}
int main(int argc, char **argv) {
FILE *fp;
fp=fopen(argv[4],"w");
fclose(fp);
strcpy(s1,argv[1]);
strcpy(s2,argv[2]);
strcpy(s4,argv[4]);
int N;
pthread_t threads[255];
printf("ENTER MAX THREADS: ");
scanf("%d",&N);
char files[255][255];
int count=0;
DIR *dp,*pdp;
struct dirent *d;
struct stat file;
dp=opendir(argv[3]);
while(d=readdir(dp)) {
char path[255];
strcpy(path,argv[3]);
strcat(path,"/");
strcat(path,d->d_name);
pdp=opendir(path);
if((pdp) && (strcmp(d->d_name,"..")==1)) {
strcpy(files[count],path);
count++;
}
}
int i;
for(i=0;i<N;i++) {
pthread_create(&threads[i],NULL,func_thread,(void*)files[i]);
z++;
}
for(i=N;i<count;i++) {
while(z==N) {}
pthread_create(&threads[i],NULL,func_thread,(void*)files[i]);
z++;
}
pthread_create(&threads[i+1],NULL,func_thread,(void*)argv[3]);
pthread_join(threads[i+1]);
return 0;
}