changeset 32385:8d841a288ca7

Move OS-fixup hacks in init code into a separate function.
author reimar
date Sat, 09 Oct 2010 15:14:33 +0000
parents 21cd61f89753
children ce1c7ac2e3d4
files mpcommon.c
diffstat 1 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mpcommon.c	Sat Oct 09 15:10:08 2010 +0000
+++ b/mpcommon.c	Sat Oct 09 15:14:33 2010 +0000
@@ -366,6 +366,29 @@
 }
 
 /**
+ * Code to fix any kind of insane defaults some OS might have.
+ * Currently mostly fixes for insecure-by-default Windows.
+ */
+static void sanitize_os(void)
+{
+#if defined(__MINGW32__) || defined(__CYGWIN__)
+    HMODULE kernel32 = GetModuleHandle("Kernel32.dll");
+    BOOL WINAPI (*setDEP)(DWORD) = NULL;
+    BOOL WINAPI (*setDllDir)(LPCTSTR) = NULL;
+    if (kernel32) {
+        setDEP = GetProcAddress(kernel32, "SetProcessDEPPolicy");
+        setDllDir = GetProcAddress(kernel32, "SetDllDirectoryA");
+    }
+    if (setDEP) setDEP(3);
+    if (setDllDir) setDllDir("");
+    // stop Windows from showing all kinds of annoying error dialogs
+    SetErrorMode(0x8003);
+    // request 1ms timer resolution
+    timeBeginPeriod(1);
+#endif
+}
+
+/**
  * Initialization code to be run after command-line parsing.
  */
 int common_init(void)
@@ -388,23 +411,8 @@
         }
     }
 #endif
-
-    {
-    HMODULE kernel32 = GetModuleHandle("Kernel32.dll");
-    BOOL WINAPI (*setDEP)(DWORD) = NULL;
-    BOOL WINAPI (*setDllDir)(LPCTSTR) = NULL;
-    if (kernel32) {
-        setDEP = GetProcAddress(kernel32, "SetProcessDEPPolicy");
-        setDllDir = GetProcAddress(kernel32, "SetDllDirectoryA");
-    }
-    if (setDEP) setDEP(3);
-    if (setDllDir) setDllDir("");
-    }
-    // stop Windows from showing all kinds of annoying error dialogs
-    SetErrorMode(0x8003);
-    // request 1ms timer resolution
-    timeBeginPeriod(1);
 #endif
+    sanitize_os();
 
 #ifdef CONFIG_PRIORITY
     set_priority();