mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
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.
This commit is contained in:
parent
3979fba0ac
commit
464b949059
1 changed files with 42 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue