¿Cuál es la forma correcta de usar la función stat () para probar si DIRENT es un directorio o un archivo?
Estoy teniendo problemas con la línea 'if (S_IFDIR (stbuf.st_mode))'. ¿Es esta la manera correcta de probar un directorio en el que se debe prestar asistencia? La función en este momento parece hacerlo bien para 1 o 2 bucles y luego falla y fallas de segmentación.
He intentado lo siguiente y probablemente más como la condición.
S_ISDIR(st_mode)
((st_mode & ST_IFMT) == S_IFDIR)
S_IFDIR(stbuf.st_mode)
He incluido toda la función porque me preocupa que el problema pueda estar en otra parte.
void getFolderContents(char *source, int temp){
struct stat stbuf;
int isDir;
dirPnt = opendir(source);
if(dirPnt != NULL){
while(entry = readdir(dirPnt)){
char *c = entry->d_name;
if(strcmp(entry->d_name, cwd) == 0 || strcmp(entry->d_name, parent) == 0){
}
else{
stat(entry->d_name, &stbuf);
printf("%i %i ", S_IFMT, stbuf.st_mode);
if(S_IFDIR(stbuf.st_mode)){ //Test DIR or file
printf("DIR: %s\n", entry->d_name);
getFolderContents(entry->d_name, 0);
}
printf("FILE: %s\n", entry->d_name);
}
}
closedir(dirPnt);
}