Attempt at fixing windows build errors.
12 mm_GetPlatformError(char *buffer, size_t maxlength)
14 DWORD dw = GetLastError();
16 FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
19 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
28 mm_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params)
30 size_t len = vsnprintf(buffer, maxlength, fmt, params);
42 mm_Format(char *buffer, size_t maxlength, const char *fmt, ...)
48 len = mm_FormatArgs(buffer, maxlength, fmt, ap);
55 mm_PathFormat(char *buffer, size_t maxlen, const char *fmt, ...)
61 len = mm_FormatArgs(buffer, maxlen, fmt, ap);
64 for (size_t i = 0; i < len; i++)
66 if (buffer[i] == ALT_SEP_CHAR)
67 buffer[i] = PATH_SEP_CHAR;
74 mm_TrimLeft(char *buffer)
76 /* Let's think of this as our iterator */
79 /* Make sure the buffer isn't null */
82 /* Add up number of whitespace characters */
83 while(isspace((unsigned char) *i))
86 /* If whitespace chars in buffer then adjust string so first non-whitespace char is at start of buffer */
88 memmove(buffer, i, (strlen(i) + 1) * sizeof(char));
93 mm_TrimRight(char *buffer)
95 /* Make sure buffer isn't null */
98 size_t len = strlen(buffer);
100 /* Loop through buffer backwards while replacing whitespace chars with null chars */
101 for (size_t i = len - 1; i >= 0; i--)
103 if (isspace((unsigned char) buffer[i]))
111 /* :TODO: this should skip string literals */
113 mm_TrimComments(char *buffer)
116 size_t len = strlen(buffer);
119 for (int i = len - 1; i >= 0; i--)
121 if (buffer[i] == '/')
123 if (++num_sc >= 2 && i==0)
138 /* size_t won't go below 0, manually break out */
147 mm_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2)
150 size_t len = strlen(str);
152 for (start = 0; start < len; start++)
154 if (!isspace(str[start]))
159 for (end = start; end < len; end++)
161 if (isspace(str[end]))
166 for (i = start; i < end; i++, c++)
174 for (start = end; start < len; start++)
176 if (!isspace(str[start]))
180 for (c = 0; start < len; start++, c++)
184 buf2[c] = str[start];
190 mm_PathCmp(const char *path1, const char *path2)
192 size_t pos1 = 0, pos2 = 0;
196 if (path1[pos1] == '\0' || path2[pos2] == '\0')
197 return (path1[pos1] == path2[pos2]);
199 if (path1[pos1] == PATH_SEP_CHAR)
201 if (path2[pos2] != PATH_SEP_CHAR)
204 /* Look for extra path chars */
205 while (path1[++pos1])
207 if (path1[pos1] != PATH_SEP_CHAR)
210 while (path2[++pos2])
212 if (path2[pos2] != PATH_SEP_CHAR)
218 /* If we're at a different non-alphanumeric, the next character MUST match */
219 if ((((unsigned)path1[pos1] & 0x80) && path1[pos1] != path2[pos2])
221 !isalpha(path1[pos1]) && (path1[pos1] != path2[pos2])
228 if (toupper(path1[pos1]) != toupper(path2[pos2]))
230 if (path1[pos1] != path2[pos2])
242 mm_ResolvePath(const char *path, char *buffer, size_t maxlength)
245 return _fullpath(buffer, path, maxlength) != NULL;
246 #elif defined __linux__
247 assert(maxlength >= PATH_MAX);
248 return realpath(path, buffer) != NULL;
253 mm_LoadLibrary(const char *path, char *buffer, size_t maxlength)
258 lib = (void*)LoadLibrary(path);
262 mm_GetPlatformError(buffer, maxlength);
265 #elif defined __linux__
266 lib = dlopen(path, RTLD_NOW);
270 mm_Format(buffer, maxlength, "%s", dlerror());
279 mm_GetLibAddress(void *lib, const char *name)
282 return GetProcAddress((HMODULE)lib, name);
283 #elif defined __linux__
284 return dlsym(lib, name);
289 mm_UnloadLibrary(void *lib)
292 FreeLibrary((HMODULE)lib);
299 mm_GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength)
302 MEMORY_BASIC_INFORMATION mem;
303 if (!VirtualQuery(pAddr, &mem, sizeof(mem)))
305 if (mem.AllocationBase == NULL)
307 HMODULE dll = (HMODULE)mem.AllocationBase;
308 GetModuleFileName(dll, (LPTSTR)buffer, maxlength);
309 #elif defined __linux__
311 if (!dladdr(pAddr, &info))
313 if (!info.dli_fbase || !info.dli_fname)
315 const char *dllpath = info.dli_fname;
316 snprintf(buffer, maxlength, "%s", dllpath);