mirror of https://github.com/encounter/SDL.git
Check to see if the file exists in the base path before returning it
This commit is contained in:
parent
c4cf63f812
commit
0ffd985972
|
@ -30,6 +30,7 @@ GetNearbyFilename(const char *file)
|
||||||
base = SDL_GetBasePath();
|
base = SDL_GetBasePath();
|
||||||
|
|
||||||
if (base != NULL) {
|
if (base != NULL) {
|
||||||
|
SDL_RWops *rw;
|
||||||
size_t len = SDL_strlen(base) + SDL_strlen(pathsep) + SDL_strlen(file) + 1;
|
size_t len = SDL_strlen(base) + SDL_strlen(pathsep) + SDL_strlen(file) + 1;
|
||||||
|
|
||||||
path = SDL_malloc(len);
|
path = SDL_malloc(len);
|
||||||
|
@ -42,13 +43,21 @@ GetNearbyFilename(const char *file)
|
||||||
|
|
||||||
SDL_snprintf(path, len, "%s%s%s", base, pathsep, file);
|
SDL_snprintf(path, len, "%s%s%s", base, pathsep, file);
|
||||||
SDL_free(base);
|
SDL_free(base);
|
||||||
} else {
|
|
||||||
path = SDL_strdup(file);
|
rw = SDL_RWFromFile(path, "rb");
|
||||||
if (path == NULL) {
|
if (rw) {
|
||||||
SDL_OutOfMemory();
|
SDL_RWclose(rw);
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Couldn't find the file in the base path */
|
||||||
|
SDL_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path = SDL_strdup(file);
|
||||||
|
if (path == NULL) {
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue