SameBoy/SDL/utils.c

43 lines
853 B
C
Raw Permalink Normal View History

#include <SDL2/SDL.h>
2017-05-24 18:44:43 +00:00
#include <stdio.h>
#include <string.h>
#include "utils.h"
const char *executable_folder(void)
{
static const char *ret = NULL;
if (!ret) {
ret = SDL_GetBasePath();
if (!ret) {
ret = "./";
2017-05-24 18:44:43 +00:00
}
}
return ret;
2017-05-24 18:44:43 +00:00
}
char *executable_relative_path(const char *filename)
{
static char path[1024];
snprintf(path, sizeof(path), "%s%s", executable_folder(), filename);
2017-05-24 18:44:43 +00:00
return path;
}
void replace_extension(const char *src, size_t length, char *dest, const char *ext)
{
memcpy(dest, src, length);
dest[length] = 0;
/* Remove extension */
for (size_t i = length; i--;) {
if (dest[i] == '/') break;
if (dest[i] == '.') {
dest[i] = 0;
break;
}
}
/* Add new extension */
strcat(dest, ext);
}