summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Troshchinskiy <vtroshchinskiy@qindel.com>2017-08-04 15:05:31 +0200
committerTanu Kaskinen <tanuk@iki.fi>2017-08-05 06:49:25 +0300
commit464b949059820698d9b0fe8583ecefb0940adc58 (patch)
tree61592da3336a3ec3307b89664f057fe640606871
parent3979fba0ac01327664fd43397bbf91fb8169101d (diff)
downloadpulseaudio-464b949059820698d9b0fe8583ecefb0940adc58.tar.gz
conf-parser: provide a replacement for scandir on Win32
PA builds fine on MinGW except for the use of the scandir function in pulsecore/conf-parser.c, so I provided a Win32 implementation. With this patch the latest code builds on Win32 without problems.
-rw-r--r--src/pulsecore/conf-parser.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index 60345adf1..73b7061f4 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -153,9 +153,11 @@ static int parse_line(pa_config_parser_state *state) {
return normal_assignment(state);
}
+#ifndef OS_IS_WIN32
static int conf_filter(const struct dirent *entry) {
return pa_endswith(entry->d_name, ".conf");
}
+#endif
/* Go through the file and parse each line */
int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, pa_proplist *proplist, bool use_dot_d,
@@ -218,6 +220,45 @@ finish:
fclose(f);
if (use_dot_d) {
+#ifdef OS_IS_WIN32
+ char *dir_name = pa_sprintf_malloc("%s.d", filename);
+ char *pattern = pa_sprintf_malloc("%s\\*.conf", dir_name);
+ HANDLE fh;
+ WIN32_FIND_DATA wfd;
+
+ fh = FindFirstFile(pattern, &wfd);
+ if (fh != INVALID_HANDLE_VALUE) {
+ do {
+ if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ char *filename2 = pa_sprintf_malloc("%s\\%s", dir_name, wfd.cFileName);
+ pa_config_parse(filename2, NULL, t, proplist, false, userdata);
+ pa_xfree(filename2);
+ }
+ } while (FindNextFile(fh, &wfd));
+ FindClose(fh);
+ } else {
+ DWORD err = GetLastError();
+
+ if (err == ERROR_PATH_NOT_FOUND) {
+ pa_log_debug("Pattern %s did not match any files, ignoring.", pattern);
+ } else {
+ LPVOID msgbuf;
+ DWORD fret = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&msgbuf, 0, NULL);
+
+ if (fret != 0) {
+ pa_log_warn("FindFirstFile(%s) failed with error %ld (%s), ignoring.", pattern, err, (char*)msgbuf);
+ LocalFree(msgbuf);
+ } else {
+ pa_log_warn("FindFirstFile(%s) failed with error %ld, ignoring.", pattern, err);
+ pa_log_warn("FormatMessage failed with error %ld", GetLastError());
+ }
+ }
+ }
+
+ pa_xfree(pattern);
+ pa_xfree(dir_name);
+#else
char *dir_name;
int n;
struct dirent **entries = NULL;
@@ -247,6 +288,7 @@ finish:
}
pa_xfree(dir_name);
+#endif
}
return r;