Answered step by step
Verified Expert Solution
Question
1 Approved Answer
why does this code segfault? void searchDirectory(void path) char base(char *)path; printf( %s , base) ; DIR *dir opendir(base); struct dirent *newfile; char buf
why does this code segfault?
void searchDirectory(void path) char base(char *)path; printf( "%s " , base) ; DIR *dir opendir(base); struct dirent *newfile; char buf [2048]0 while( (newfile -readdir(dir)) NULL) // regular files if (newfile->d_typeDT_REG) else if (newfile->d_typeDTDIR)// folders if ( ! strp (newfile--d name,".") | | ! strpnewfile--d name,'..") ){ continue; if (strcmp (base,"./")) I/.name> .ame sprintf(buf, "%s%s ", base, newfile->d_name); while (pthread mutex_lock(&mallocThread)1 pNode *node malloc(sizeof (struct pNode)); pthread_mutex_unlock(&mallocThread); pthread_create(&(node->threadID), NULL, &searchDirectory, (void*) buf); addToJoinLockLink(node); //searchDirectory ((void *)buf); else /ame/test alex -> .ame/test/alex sprintf(buf, "%s/%s" , base, newfile->d_name); while (pthread mutex_lock &mallocThread)11 pNode node-malloc(sizeof (struct pNode)); pthread mutex unlock (&mallocThread); //searchDirectory( (void *)buf) pthread_create(&(node->threadID), NULL, &searchDirectory, (void*) buf); addToJoinLockLink (node); pthread exit(NULL)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started