From: Maarten Bosmans Date: Thu, 6 Jan 2011 01:10:45 +0000 (+0100) Subject: Implement some functions for win32 X-Git-Tag: submit/2.0-panda/20130828.192557~772^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6d43367053bbc0d99acd7a21a21e15a5aaae659;p=profile%2Fivi%2Fpulseaudio-panda.git Implement some functions for win32 And disable building binaries for win32 that make no sense there --- diff --git a/src/Makefile.am b/src/Makefile.am index 55e6322..c17c225 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) diff --git a/src/daemon/main.c b/src/daemon/main.c index 5aeb9bc..243e7c0 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -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 diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c index d671e36..684bc01 100644 --- a/src/pulsecore/authkey.c +++ b/src/pulsecore/authkey.c @@ -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; diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index f2a0946..04a2341 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -91,6 +91,10 @@ #include #endif +#ifndef ENOTSUP +#define ENOTSUP 135 +#endif + #ifdef HAVE_PWD_H #include #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."