summaryrefslogtreecommitdiffhomepage
path: root/src/os-win32.h
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2022-03-24 02:06:28 +0000
committerMichael Smith <mikesmiffy128@gmail.com>2022-03-24 04:38:25 +0000
commit00ad7cdd3d05d09a43bda972c823fdc440feabb9 (patch)
tree7f9725341e598f273fc1fb6ca0803c794bb67698 /src/os-win32.h
parentb18326a75078530df7712667f41b4ea354e1da3e (diff)
Clean up gameinfo_init() and other random stuff
- Just ask the engine for the game directory instead of doing the stupid argv sniffing hacks from the early days of trying to get the damn thing working. - Also add some other path variables, functions and whatnot, and do some other minor tidying up. - Also also, another damn copyright year, somebody please help me. Unfortunate negative effect off this change: con_init() no longer reports the game name, because it has to happen before gameinfo_init(). I've decided I don't really care, though.
Diffstat (limited to 'src/os-win32.h')
-rw-r--r--src/os-win32.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/os-win32.h b/src/os-win32.h
index fb31d67..c7c0bae 100644
--- a/src/os-win32.h
+++ b/src/os-win32.h
@@ -41,6 +41,7 @@ typedef unsigned short os_char;
#define _stat64(path, buf) _wstat64(path, buf)
#define os_stat _stat64
#define os_getenv _wgetenv
+#define os_getcwd _wgetcwd
#define OS_DLSUFFIX ".dll"
@@ -50,6 +51,18 @@ static inline void *os_dlsym(void *m, const char *s) {
return (void *)GetProcAddress(m, s);
}
+static inline bool os_dlfile(void *m, unsigned short *buf, int sz) {
+ unsigned int n = GetModuleFileNameW(m, buf, sz);
+ if (n == 0 || n == sz) return false;
+ // get the canonical capitalisation, as for some reason GetModuleFileName()
+ // returns all lowercase. this doesn't really matter except it looks nicer
+ GetLongPathNameW(buf, buf, n + 1);
+ // the drive letter will also be lower case, if it is an actual drive letter
+ // of course. it should be; I'm not gonna lose sleep over UNC paths and such
+ if (buf[0] >= L'a' && buf[0] <= L'z' && buf[1] == L':') buf[0] &= ~32u;
+ return true;
+}
+
static inline bool os_mprot(void *addr, int len, int fl) {
unsigned long old;
return !!VirtualProtect(addr, len, fl, &old);