From 464b949059820698d9b0fe8583ecefb0940adc58 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Fri, 4 Aug 2017 15:05:31 +0200 Subject: 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. --- src/pulsecore/conf-parser.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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; -- cgit v1.2.1