summary refs log tree commit diff stats
path: root/src/common/xchat.c
diff options
context:
space:
mode:
authorBerke Viktor <berkeviktor@aol.com>2011-11-25 09:59:39 +0100
committerBerke Viktor <berkeviktor@aol.com>2011-11-25 09:59:39 +0100
commitfb1a986332a7ff6db6f2a70df447c5d484af7cdc (patch)
tree757626c00736c07d99b8242171e2350195b4a9fd /src/common/xchat.c
parentb15fe1ddf13de866d1ad8068db1d4632b5bbe094 (diff)
option to allow only one instance xchat to run
Diffstat (limited to 'src/common/xchat.c')
-rw-r--r--src/common/xchat.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/common/xchat.c b/src/common/xchat.c
index ba2f5d41..8dca6de8 100644
--- a/src/common/xchat.c
+++ b/src/common/xchat.c
@@ -26,7 +26,9 @@
 #define WANTSOCKET
 #include "inet.h"
 
-#ifndef WIN32
+#ifdef WIN32
+#include <windows.h>
+#else
 #include <sys/wait.h>
 #include <signal.h>
 #endif
@@ -903,7 +905,11 @@ int
 main (int argc, char *argv[])
 {
 	int ret;
-	
+
+#ifdef WIN32
+	HANDLE mutex;
+#endif
+
 	srand (time (0));	/* CL: do this only once! */
 
 #ifdef SOCKS
@@ -920,6 +926,21 @@ main (int argc, char *argv[])
 
 	load_config ();
 
+#ifdef WIN32
+	if (prefs.gui_one_instance)
+	{
+		DWORD error;
+
+		mutex = CreateMutex (NULL, TRUE, "Local\xchat");
+		error = GetLastError ();
+
+		if (error == ERROR_ALREADY_EXISTS || mutex == NULL)
+		{
+			return 1;
+		}
+	}
+#endif
+
 #ifdef USE_LIBPROXY
 	libproxy_factory = px_proxy_factory_new();
 #endif
@@ -945,6 +966,11 @@ main (int argc, char *argv[])
 
 #ifdef WIN32
 	WSACleanup ();
+
+	if (prefs.gui_one_instance)
+	{
+		CloseHandle (mutex);
+	}
 #endif
 
 	return 0;