diff common/util.c @ 675:4ad764bfb39c

Add writing of the NSS line into the registry
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 27 Jun 2014 18:53:52 +0200
parents d4766b4922c9
children 216a65d7fc4b
line wrap: on
line diff
--- a/common/util.c	Fri Jun 27 16:18:10 2014 +0200
+++ b/common/util.c	Fri Jun 27 18:53:52 2014 +0200
@@ -20,6 +20,40 @@
 #endif
 
 #ifdef WIN32
+char * get_install_dir()
+{
+  wchar_t wPath[MAX_PATH];
+  char *utf8path = NULL;
+  char *dirsep = NULL;
+
+  if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) 
+    {
+      PRINTLASTERROR ("Failed to obtain module file name. Path too long?");
+      return NULL;
+    }
+
+  /* wPath might not be 0 terminated */
+  wPath[MAX_PATH - 1] = '\0';
+
+  utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH));
+
+  if (utf8path == NULL)
+    {
+      ERRORPRINTF ("Failed to convert module path to utf-8");
+      return NULL;
+    }
+
+  /* Cut away the executable name */
+  dirsep = strrchr(utf8path, '\\');
+  if (dirsep == NULL)
+    {
+      ERRORPRINTF ("Failed to find directory seperator.");
+      return NULL;
+    }
+  *dirsep = '\0';
+  return utf8path;
+}
+
 static PSID
 copy_sid(PSID from)
 {

http://wald.intevation.org/projects/trustbridge/