Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedwhy 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago