Fixed a couple Windows errors.

This commit is contained in:
Scott Duensing 2020-03-08 19:14:52 -05:00
parent f7a10cc921
commit d9480da470
3 changed files with 12 additions and 1 deletions

View file

@ -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));

View file

@ -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) {

View file

@ -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);