Code:
#define PORTAGE_DIR "."
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
int main() {
/* Holds info for the main portage directory. */
DIR *master = opendir(PORTAGE_DIR);
struct dirent *master_dirent;
struct stat master_stat;
/* Holds info for the crawler which goes in every category folder. */
DIR *crawl;
struct dirent *crawl_dirent;
struct stat crawl_stat;
char *open = NULL;
if(master != NULL) {
/* Read in every category folder. */
while( (master_dirent = readdir(master)) != 0 ) {
if( stat(master_dirent->d_name, &master_stat) == 0 ) {
/* Check to see if its a folder. */
if( S_ISDIR(master_stat.st_mode) != 0 ) {
/* It is a director, enter and crawl. */
if( nodots(master_dirent->d_name) == 0 ) {
open = malloc( strlen(PORTAGE_DIR) + strlen(master_dirent->d_name) - 1 );
sprintf("%s%s", open, PORTAGE_DIR, master_dirent->d_name); //crashes here
crawl = opendir(open);
while( (crawl_dirent = readdir(crawl)) != 0 ) {
if( stat(crawl_dirent->d_name, &crawl_stat) == 0 ) {
if( S_ISDIR(crawl_stat.st_mode) != 0 ) {
printf("%s\n", crawl_dirent->d_name);
}
}
}
closedir(crawl);
}
}
}
}
closedir(master);
} else {
perror("Error: ");
}
return 0;
}
int nodots(char *src) {
if( strcmp(src, ".") == 0 )
return 1;
if( strcmp(src, "..") == 0 )
return 1;
return 0;
}
Im now trying to see if the directories are the dots(for lack of a better name). My idea was to just sprintf it, but it crashes there. Printf letsme print it as a string, whats wrong here?