]> code.delx.au - pulseaudio/commitdiff
Implement some functions for win32
authorMaarten Bosmans <mkbosmans@gmail.com>
Thu, 6 Jan 2011 01:10:45 +0000 (02:10 +0100)
committerMaarten Bosmans <mkbosmans@gmail.com>
Thu, 17 Feb 2011 11:02:30 +0000 (12:02 +0100)
And disable building binaries for win32 that make no sense there

src/Makefile.am
src/daemon/main.c
src/pulsecore/authkey.c
src/pulsecore/core-util.c

index 55e6322da4068c1a4fd62a6e7ea008a4d27a4751..c17c225ded99d5f646e85a4f0c8919adafb317ac 100644 (file)
@@ -177,8 +177,11 @@ endif
 
 bin_PROGRAMS += \
                pacat \
-               pactl \
-               pasuspender
+               pactl
+
+if !OS_IS_WIN32
+bin_PROGRAMS += pasuspender
+endif
 
 if HAVE_AF_UNIX
 bin_PROGRAMS += pacmd
@@ -256,9 +259,7 @@ TESTS = \
                envelope-test \
                proplist-test \
                lock-autospawn-test \
-               prioq-test \
-               sigbus-test \
-               usergroup-test
+               prioq-test
 
 TESTS_BINARIES = \
                mainloop-test \
@@ -295,9 +296,16 @@ TESTS_BINARIES = \
                rtstutter \
                stripnul \
                lock-autospawn-test \
-               prioq-test \
+               prioq-test
+
+if !OS_IS_WIN32
+TESTS += \
+               sigbus-test \
+               usergroup-test
+TESTS_BINARIES += \
                sigbus-test \
                usergroup-test
+endif
 
 if HAVE_SIGXCPU
 #TESTS += \
@@ -326,9 +334,11 @@ TESTS_BINARIES += \
 endif
 
 if !OS_IS_DARWIN
+if !OS_IS_WIN32
 TESTS_BINARIES += \
                once-test
 endif
+endif
 
 if BUILD_TESTS_DEFAULT
 noinst_PROGRAMS = $(TESTS_BINARIES)
index 5aeb9bc60d2b87547aedc0d6428bf5bdb4433120..243e7c0a2bfd8b5d5b71c37dbfce6df02948ded6 100644 (file)
@@ -1078,7 +1078,7 @@ finish:
     }
 
 #ifdef OS_IS_WIN32
-    if (win32_timer)
+    if (mainloop && win32_timer)
         pa_mainloop_get_api(mainloop)->time_free(win32_timer);
 #endif
 
index d671e367c30a41ff46120e8bfab42e594b89224e..684bc010125fd53b579693d80b8eb923bd9e128a 100644 (file)
@@ -151,7 +151,7 @@ static char *normalize_path(const char *fn) {
 #ifndef OS_IS_WIN32
     if (fn[0] != '/') {
 #else
-    if (strlen(fn) < 3 || !isalpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
+    if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
 #endif
         char *homedir, *s;
 
index f2a09463337401071e81543e741fc082e1c6eac8..04a2341f972f4c883fe7639706d18c313b61ffce 100644 (file)
 #include <windows.h>
 #endif
 
+#ifndef ENOTSUP
+#define ENOTSUP   135
+#endif
+
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #endif
@@ -147,20 +151,18 @@ static pa_strlist *recorded_env = NULL;
 #define PULSE_ROOTENV "PULSE_ROOT"
 
 int pa_set_root(HANDLE handle) {
-    char library_path[MAX_PATH + sizeof(PULSE_ROOTENV) + 1], *sep;
-
-    strcpy(library_path, PULSE_ROOTENV "=");
+    char library_path[MAX_PATH], *sep;
 
     /* FIXME: Needs to set errno */
 
-    if (!GetModuleFileName(handle, library_path + sizeof(PULSE_ROOTENV), MAX_PATH))
+    if (!GetModuleFileName(handle, library_path, MAX_PATH))
         return 0;
 
     sep = strrchr(library_path, PA_PATH_SEP_CHAR);
     if (sep)
         *sep = '\0';
 
-    if (_putenv(library_path) < 0)
+    if (!SetEnvironmentVariable(PULSE_ROOTENV, library_path))
         return 0;
 
     return 1;
@@ -696,14 +698,21 @@ int pa_make_realtime(int rtprio) {
             pa_log_info("Successfully enabled SCHED_RR scheduling for thread, with priority %i, which is lower than the requested %i.", p, rtprio);
             return 0;
         }
+#elif defined(OS_IS_WIN32)
+    /* Windows only allows realtime scheduling to be set on a per process basis.
+     * Therefore, instead of making the thread realtime, just give it the highest non-realtime priority. */
+    if(SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL)) {
+        pa_log_info("Successfully enabled THREAD_PRIORITY_TIME_CRITICAL scheduling for thread.");
+        return 0;
+    }
 
-    pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno));
-    return -1;
+    pa_log_warn("SetThreadPriority() failed: 0x%08X", GetLastError());
+    errno = EPERM;
 #else
-
     errno = ENOTSUP;
-    return -1;
 #endif
+    pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno));
+    return -1;
 }
 
 static int set_nice(int nice_level) {
@@ -1499,6 +1508,9 @@ static int make_random_dir_and_link(mode_t m, const char *k) {
         errno = saved_errno;
         return -1;
     }
+#else
+    pa_xfree(p);
+    return -1;
 #endif
 
     pa_xfree(p);
@@ -1558,6 +1570,7 @@ char *pa_get_runtime_dir(void) {
                 goto fail;
             }
 
+#ifdef HAVE_SYMLINK
             /* Hmm, so the runtime directory didn't exist yet, so let's
              * create one in /tmp and symlink that to it */
 
@@ -1570,6 +1583,11 @@ char *pa_get_runtime_dir(void) {
 
                 goto fail;
             }
+#else
+            /* No symlink possible, so let's just create the runtime directly */
+            if (!mkdir(k))
+                goto fail;
+#endif
 
             return k;
         }
@@ -2539,7 +2557,11 @@ void pa_set_env(const char *key, const char *value) {
 
     /* This is not thread-safe */
 
+#ifdef OS_IS_WIN32
+    SetEnvironmentVariable(key, value);
+#else
     setenv(key, value, 1);
+#endif
 }
 
 void pa_set_env_and_record(const char *key, const char *value) {
@@ -2564,7 +2586,11 @@ void pa_unset_env_recorded(void) {
         if (!s)
             break;
 
+#ifdef OS_IS_WIN32
+        SetEnvironmentVariable(s, NULL);
+#else
         unsetenv(s);
+#endif
         pa_xfree(s);
     }
 }
@@ -2682,11 +2708,22 @@ char *pa_session_id(void) {
 }
 
 char *pa_uname_string(void) {
+#ifdef HAVE_UNAME
     struct utsname u;
 
     pa_assert_se(uname(&u) >= 0);
 
     return pa_sprintf_malloc("%s %s %s %s", u.sysname, u.machine, u.release, u.version);
+#endif
+#ifdef OS_IS_WIN32
+    OSVERSIONINFO i;
+
+    pa_zero(i);
+    i.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    pa_assert_se(GetVersionEx(&i));
+
+    return pa_sprintf_malloc("Windows %d.%d (%d) %s", i.dwMajorVersion, i.dwMinorVersion, i.dwBuildNumber, i.szCSDVersion);
+#endif
 }
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
@@ -2835,10 +2872,17 @@ char *pa_realpath(const char *path) {
         char *path_buf;
         path_buf = pa_xmalloc(PATH_MAX);
 
+#if defined(OS_IS_WIN32)
+        if (!(t = _fullpath(path_buf, path, _MAX_PATH))) {
+            pa_xfree(path_buf);
+            return NULL;
+        }
+#else
         if (!(t = realpath(path, path_buf))) {
             pa_xfree(path_buf);
             return NULL;
         }
+#endif
     }
 #else
 #error "It's not clear whether this system supports realpath(..., NULL) like GNU libc does. If it doesn't we need a private version of realpath() here."