src/pcm/Makefile src/pcm/scopes/Makefile \
src/rawmidi/Makefile src/timer/Makefile \
src/hwdep/Makefile src/seq/Makefile src/ucm/Makefile \
- src/compat/Makefile src/alisp/Makefile src/conf/Makefile \
+ src/compat/Makefile src/alisp/Makefile \
+ src/conf/Makefile src/conf/alsa.conf.d/Makefile \
src/conf/cards/Makefile \
src/conf/pcm/Makefile \
modules/Makefile modules/mixer/Makefile modules/mixer/simple/Makefile \
#include <stdarg.h>
#include <limits.h>
#include <sys/stat.h>
+#include <dirent.h>
#include <locale.h>
#include "local.h"
#ifdef HAVE_LIBPTHREAD
return err;
}
+static int config_filename_filter(const struct dirent *dirent)
+{
+ size_t flen;
+
+ if (dirent == NULL)
+ return 0;
+ if (dirent->d_type == DT_DIR)
+ return 0;
+
+ flen = strlen(dirent->d_name);
+ if (flen <= 5)
+ return 0;
+
+ if (strncmp(&dirent->d_name[flen-5], ".conf", 5) == 0)
+ return 1;
+
+ return 0;
+}
+
+static int config_file_open(snd_config_t *root, const char *filename)
+{
+ snd_input_t *in;
+ int err;
+
+ err = snd_input_stdio_open(&in, filename, "r");
+ if (err >= 0) {
+ err = snd_config_load(root, in);
+ snd_input_close(in);
+ if (err < 0)
+ SNDERR("%s may be old or corrupted: consider to remove or fix it", filename);
+ } else
+ SNDERR("cannot access file %s", filename);
+
+ return err;
+}
+
/**
* \brief Loads and parses the given configurations files.
* \param[in] root Handle to the root configuration node.
}
} while (hit);
for (idx = 0; idx < fi_count; idx++) {
- snd_input_t *in;
+ struct stat st;
if (!errors && access(fi[idx].name, R_OK) < 0)
continue;
- err = snd_input_stdio_open(&in, fi[idx].name, "r");
- if (err >= 0) {
- err = snd_config_load(root, in);
- snd_input_close(in);
- if (err < 0) {
- SNDERR("%s may be old or corrupted: consider to remove or fix it", fi[idx].name);
- goto _err;
- }
- } else {
- SNDERR("cannot access file %s", fi[idx].name);
+ if (stat(fi[idx].name, &st) < 0) {
+ SNDERR("cannot stat file/directory %s", fi[idx].name);
+ continue;
}
+ if (S_ISDIR(st.st_mode)) {
+ struct dirent **namelist;
+ int n;
+
+ n = scandir(fi[idx].name, &namelist, config_filename_filter, versionsort);
+ if (n > 0) {
+ int j;
+ err = 0;
+ for (j = 0; j < n; ++j) {
+ if (err >= 0) {
+ int sl = strlen(fi[idx].name) + strlen(namelist[j]->d_name) + 2;
+ char *filename = malloc(sl);
+ snprintf(filename, sl, "%s/%s", fi[idx].name, namelist[j]->d_name);
+ filename[sl-1] = '\0';
+
+ err = config_file_open(root, filename);
+ free(filename);
+ }
+ free(namelist[j]);
+ }
+ free(namelist);
+ if (err < 0)
+ goto _err;
+ }
+ } else if (config_file_open(root, fi[idx].name) < 0)
+ goto _err;
}
*dst = NULL;
err = 0;