Fix missing path concatination

This commit is contained in:
Tobias Reisinger 2020-11-19 01:25:52 +01:00
parent 0c13c03a73
commit ce59bb364f

View file

@ -348,20 +348,34 @@ config_load_directory(config_t *config, const char *directory_name)
exit(1); exit(1);
} }
// Process each entry.
while((directory_entry = readdir(directory)) != NULL) while((directory_entry = readdir(directory)) != NULL)
{ {
struct stat sb; struct stat sb;
const char *entry_name = directory_entry->d_name; 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)) if(S_ISREG(sb.st_mode))
{ {
config_load_file(config, entry_name); config_load_file(config, path);
} }
free(path);
} }
// Close directory and exit. // Close directory and exit.