diff util.c @ 742:2e1b3b258523

Make Windows port a little less half-assed
author Michael Pavone <pavone@retrodev.com>
date Tue, 01 Apr 2014 21:12:00 -0700
parents 80a67be1770b
children fc68992cf18d
line wrap: on
line diff
--- a/util.c	Tue Apr 01 19:43:58 2014 -0700
+++ b/util.c	Tue Apr 01 21:12:00 2014 -0700
@@ -75,7 +75,41 @@
 	exe_str = str;
 }
 
-#ifndef _WIN32
+#ifdef _WIN32
+#include "Shlobj.h"
+#include "Windows.h"
+
+char * get_home_dir()
+{
+	static char path[MAX_PATH];
+	SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path);
+	return path;
+}
+
+char * get_exe_dir()
+{
+	static char path[MAX_PATH];
+	HMODULE module = GetModuleHandleA(NULL);
+	GetModuleFileNameA(module, path, MAX_PATH);
+
+	int pathsize = strlen(path);
+	for(char * cur = path + pathsize - 1; cur != path; cur--)
+	{
+		if (*cur == '\\') {
+			*cur = 0;
+			break;
+		}
+	}
+	return path;
+}
+
+#else
+
+char * get_home_dir()
+{
+	return getenv("HOME");
+}
+
 char * readlink_alloc(char * path)
 {
 	char * linktext = NULL;
@@ -139,4 +173,5 @@
 	}
 	return exe_dir;
 }
+
 #endif