Skip to content

Commit

Permalink
win: to coexist with other SDL2
Browse files Browse the repository at this point in the history
/fix #170
  • Loading branch information
VitoVan committed Nov 16, 2023
1 parent 7268344 commit 452e851
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/calm.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ const char *get_sbcl_path() {
return sbcl_path;
}

void prepend(char *s1, char *s2) {
int len1 = strlen(s1);
int len2 = strlen(s2);

// Make s1 big enough to hold both strings
s1 = realloc(s1, len1 + len2 + 1);

// Move s1's original contents to the end
memmove(s1 + len2, s1, len1 + 1);

// Copy s2 to the beginning of s1
memcpy(s1, s2, len2);
}

/*
* return the new value for
* Linux: LD_LIBRARY_PATH
Expand All @@ -149,10 +163,21 @@ const char *get_lib_env() {
(strlen(ori_lib_env) + strlen(lib_path) + strlen(path_separator) + 1) *
sizeof(char));
strcpy(lib_env, ori_lib_env);

#if defined _WIN32
// on Windows, we need to prepend PATH to coexist (override) with other
// incompatible version of SDL2 under system env settings of PATH
if (strlen(ori_lib_env) > 0) {
prepend(lib_env, path_separator);
}
prepend(lib_env, lib_path);
#else
if (strlen(ori_lib_env) > 0) {
strcat(lib_env, path_separator);
}
strcat(lib_env, lib_path);
#endif

printf("LIB_ENV=%s\n", lib_env);
return lib_env;
}
Expand Down

0 comments on commit 452e851

Please sign in to comment.