comparison 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
comparison
equal deleted inserted replaced
741:80a67be1770b 742:2e1b3b258523
73 void set_exe_str(char * str) 73 void set_exe_str(char * str)
74 { 74 {
75 exe_str = str; 75 exe_str = str;
76 } 76 }
77 77
78 #ifndef _WIN32 78 #ifdef _WIN32
79 #include "Shlobj.h"
80 #include "Windows.h"
81
82 char * get_home_dir()
83 {
84 static char path[MAX_PATH];
85 SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path);
86 return path;
87 }
88
89 char * get_exe_dir()
90 {
91 static char path[MAX_PATH];
92 HMODULE module = GetModuleHandleA(NULL);
93 GetModuleFileNameA(module, path, MAX_PATH);
94
95 int pathsize = strlen(path);
96 for(char * cur = path + pathsize - 1; cur != path; cur--)
97 {
98 if (*cur == '\\') {
99 *cur = 0;
100 break;
101 }
102 }
103 return path;
104 }
105
106 #else
107
108 char * get_home_dir()
109 {
110 return getenv("HOME");
111 }
112
79 char * readlink_alloc(char * path) 113 char * readlink_alloc(char * path)
80 { 114 {
81 char * linktext = NULL; 115 char * linktext = NULL;
82 ssize_t linksize = 512; 116 ssize_t linksize = 512;
83 ssize_t cursize = 0; 117 ssize_t cursize = 0;
137 exe_dir = linktext; 171 exe_dir = linktext;
138 } 172 }
139 } 173 }
140 return exe_dir; 174 return exe_dir;
141 } 175 }
176
142 #endif 177 #endif