diff --git a/singe/singe.c b/singe/singe.c index 4ff0fc3fc..362c05a19 100644 --- a/singe/singe.c +++ b/singe/singe.c @@ -2219,7 +2219,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) { free(temp); // Load mappings in game script dir temp = strdup(_confScriptFile); - temp2 = strndup(temp, strlen(temp) - strlen(utilGetLastPathComponent(temp))); + temp2 = utilStrndup(temp, strlen(temp) - strlen(utilGetLastPathComponent(temp))); free(temp); temp = utilCreateString("%scontrols.cfg", temp2); if (utilFileExists(temp) && luaL_dofile(_luaContext, temp)) utilDie("%s", lua_tostring(_luaContext, -1)); diff --git a/singe/util.c b/singe/util.c index fa2a41d62..125130a6e 100644 --- a/singe/util.c +++ b/singe/util.c @@ -376,6 +376,16 @@ void utilSay(char *fmt, ...) { } + +// Windows does not have strndup() so we implement our own. +char *utilStrndup( const char *s1, size_t n) { + char *copy = (char *)malloc(n + 1); + memcpy(copy, s1, n); + copy[n] = 0; + return copy; +} + + void utilTrace(char *fmt, ...) { va_list args; if (utilTraceFile) { diff --git a/singe/util.h b/singe/util.h index b1587af81..4da5210db 100644 --- a/singe/util.h +++ b/singe/util.h @@ -52,6 +52,7 @@ char *utilReadFile(char *filename, size_t *bytes); char *utilReadLine(char *haystack, size_t length, char **offset); void utilRedirectConsole(void); void utilSay(char *fmt, ...); +char *utilStrndup( const char *s1, size_t n); void utilTrace(char *fmt, ...); void utilTraceEnd(void); void utilTraceStart(char *filename);