Mercurial > retraceit
diff src/util_win.c @ 0:147b08bc7d64
Initial commit of a basic Application framework.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 23 Mar 2015 12:41:52 +0100 |
parents | |
children | 9daf778feaf1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/util_win.c Mon Mar 23 12:41:52 2015 +0100 @@ -0,0 +1,49 @@ +#ifdef WIN32 +/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=2) + * and comes with ABSOLUTELY NO WARRANTY! + * See LICENSE.txt for details. + */ + +/**@file Linux implementation of functions declared in util.h */ + +#include "util.h" +#include "strhelp.h" + +#include <windows.h> + +char * +get_install_dir() +{ + wchar_t wPath[MAX_PATH]; + char *utf8path = NULL; + char *dirsep = NULL; + + if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) + { + 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) + { + return NULL; + } + + /* Cut away the executable name */ + dirsep = strrchr(utf8path, '\\'); + if (dirsep == NULL) + { + return NULL; + } + *dirsep = '\0'; + return utf8path; +} +#endif +