summaryrefslogtreecommitdiffhomepage
path: root/src/sst.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-08-20 16:20:03 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-08-27 00:46:09 +0100
commita1998f2f7ce4153d670e2e5cb5018366517cc1ca (patch)
tree4d899fbad24c728c0b51f183c61ed6a7fb213c04 /src/sst.c
parent38fa6c52a8a26ac178a3e1f80a8317740b8e82b3 (diff)
Get things at least compiling under Linux
Nothing really works yet, but at least test.h and fastspin are fixed and some of the issues with RTTI and libdl and stuff are maybe kind of sorted, subject to more testing later. The main issue now seems to be the cvar interface not quite lining up and crashing pretty much immediately. That'll probably take a lot more debugging to figure out, which likely still won't be a priority for quite a while.
Diffstat (limited to 'src/sst.c')
-rw-r--r--src/sst.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/sst.c b/src/sst.c
index 9fd1108..3618210 100644
--- a/src/sst.c
+++ b/src/sst.c
@@ -14,6 +14,9 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef _WIN32
+#include <stdlib.h> // unsetenv
+#endif
#include <string.h>
#ifdef _WIN32
@@ -71,6 +74,8 @@ static void *ownhandle(void) {
}
return cached;
}
+
+struct gnu_link_map *_os_lmbase = 0; // XXX: stupid place to put this, oh well
#endif
#ifdef _WIN32
@@ -139,9 +144,32 @@ DEF_CCMD_HERE(sst_autoload_enable, "Register SST to load on game startup", 0) {
return;
}
// arbitrary aesthetic judgement
- for (os_char *p = relpath; *p; ++p) if (*p == L'\\') *p = L'/';
+ for (ushort *p = relpath; *p; ++p) if (*p == L'\\') *p = L'/';
#else
-#error TODO(linux): implement this, it's late right now and I can't be bothered
+ const char *p = path, *q = startdir;
+ int slash = 0;
+ int i = 1;
+ for (;; ++i) {
+ if (p[i] == '/' && (q[i] == '/' || q[i] == '\0')) slash = i;
+ if (p[i] != q[i]) break;
+ }
+ int rellen = strlen(p + slash + 1) + 1; // include \0
+ char *r = relpath;
+ if (q[i]) {
+ if (r - relpath >= PATH_MAX - 3 - rellen) {
+ errmsg_errorx("path to game is too long"); // eh...
+ return;
+ }
+ for (;;) {
+ r[0] = '.'; r[1] = '.'; r[2] = '/';
+ r += 3;
+ for (;;) {
+ if (q[++i] == '/') break;
+ if (!q[i]) goto c;
+ }
+ }
+ }
+c: memcpy(r, p + slash + 1, rellen);
#endif
int len = os_strlen(gameinfo_gamedir);
if (len + sizeof("/addons/" VDFBASENAME ".vdf") >
@@ -231,8 +259,8 @@ static void do_featureinit(void) {
"CreateInterface"))) {
errmsg_warndl("couldn't get client's CreateInterface");
}
- void *inputsystemlib = os_dlhandle(OS_LIT("bin/") OS_LIT(OS_DLPREFIX)
- OS_LIT("inputsystem") OS_LIT(OS_DLSUFFIX));
+ void *inputsystemlib = os_dlhandle(OS_LIT("bin/") OS_LIT("inputsystem")
+ OS_LIT(OS_DLSUFFIX));
if (!inputsystemlib) {
errmsg_warndl("couldn't get the input system library");
}
@@ -240,8 +268,9 @@ static void do_featureinit(void) {
"CreateInterface"))) {
errmsg_warndl("couldn't get input system's CreateInterface");
}
- inputsystem = factory_inputsystem("InputSystemVersion001", 0);
- if (!inputsystem) errmsg_warnx("missing input system interface");
+ else if (!(inputsystem = factory_inputsystem("InputSystemVersion001", 0))) {
+ errmsg_warnx("missing input system interface");
+ }
// ... and now for the real magic!
initfeatures();
@@ -398,9 +427,6 @@ static void do_unload(void) {
}
#endif
endfeatures();
-#ifdef __linux__
- if (clientlib) dlclose(clientlib);
-#endif
con_disconnect();
}