diff --git a/src/config.c b/src/config.c index cf97287..5ad161d 100644 --- a/src/config.c +++ b/src/config.c @@ -348,20 +348,34 @@ config_load_directory(config_t *config, const char *directory_name) exit(1); } - // Process each entry. - while((directory_entry = readdir(directory)) != NULL) { struct stat sb; const char *entry_name = directory_entry->d_name; - if(stat(entry_name, &sb)) + + size_t copied = 0; + + // Add 2 for '/' and '\0'. + size_t path_size = strlen(directory_name) + strlen(entry_name) + 2; + char *path = malloc(sizeof(char) * path_size); + path[0] = '\0'; + + copied += strlcat(path + copied, directory_name, path_size - copied); + if(path[copied - 1] != '/') { - LOGGER_WARNING("failed to get info for '%s': %s\n", entry_name, strerror(errno)); + copied += strlcat(path + copied, "/", path_size - copied); + } + copied += strlcat(path + copied, entry_name, path_size - copied); + + if(stat(path, &sb)) + { + LOGGER_WARNING("failed to get info for '%s': %s\n", path, strerror(errno)); } if(S_ISREG(sb.st_mode)) { - config_load_file(config, entry_name); + config_load_file(config, path); } + free(path); } // Close directory and exit.