[PATCH] core: Provide a replacement for scandir on Win32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ð? пиÑ?Ñ?ме оÑ? Ñ?еÑ?веÑ?г, 3 авгÑ?Ñ?Ñ?а 2017 г. 11:08:44 CEST полÑ?зоваÑ?елÑ? Tanu Kaskinen напиÑ?ал:
> Thanks for the patch! It would be good to get this in the upcoming
> release. Some complaints below.

Hello, I have made the fixes, and also fixed a few warnings.



---
 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 60345adf..c82c19c1 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;
-- 
2.13.3




-- 
Vadim Troshchinskiy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20170804/0c49598d/attachment.sig>


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux