mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-16 09:48:26 +00:00
testutils: use SDL_asprintf() to simplify path composition
This commit is contained in:
parent
625bc2d250
commit
623a90c47d
1 changed files with 4 additions and 13 deletions
|
@ -20,24 +20,18 @@
|
||||||
*
|
*
|
||||||
* Fails and returns NULL if out of memory.
|
* Fails and returns NULL if out of memory.
|
||||||
*/
|
*/
|
||||||
char *
|
char *GetNearbyFilename(const char *file)
|
||||||
GetNearbyFilename(const char *file)
|
|
||||||
{
|
{
|
||||||
const char *base = SDL_GetBasePath();
|
const char *base = SDL_GetBasePath();
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if (base) {
|
if (base) {
|
||||||
SDL_IOStream *rw;
|
SDL_IOStream *rw;
|
||||||
size_t len = SDL_strlen(base) + SDL_strlen(file) + 1;
|
|
||||||
|
|
||||||
path = SDL_malloc(len);
|
if (SDL_asprintf(&path, "%s%s", base, file) < 0) {
|
||||||
|
|
||||||
if (!path) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)SDL_snprintf(path, len, "%s%s", base, file);
|
|
||||||
|
|
||||||
rw = SDL_IOFromFile(path, "rb");
|
rw = SDL_IOFromFile(path, "rb");
|
||||||
if (rw) {
|
if (rw) {
|
||||||
SDL_CloseIO(rw);
|
SDL_CloseIO(rw);
|
||||||
|
@ -60,8 +54,7 @@ GetNearbyFilename(const char *file)
|
||||||
*
|
*
|
||||||
* Fails and returns NULL if out of memory.
|
* Fails and returns NULL if out of memory.
|
||||||
*/
|
*/
|
||||||
char *
|
char *GetResourceFilename(const char *user_specified, const char *def)
|
||||||
GetResourceFilename(const char *user_specified, const char *def)
|
|
||||||
{
|
{
|
||||||
if (user_specified) {
|
if (user_specified) {
|
||||||
return SDL_strdup(user_specified);
|
return SDL_strdup(user_specified);
|
||||||
|
@ -79,9 +72,7 @@ GetResourceFilename(const char *user_specified, const char *def)
|
||||||
*
|
*
|
||||||
* If height_out is non-NULL, set it to the texture height.
|
* If height_out is non-NULL, set it to the texture height.
|
||||||
*/
|
*/
|
||||||
SDL_Texture *
|
SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent, int *width_out, int *height_out)
|
||||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
|
|
||||||
int *width_out, int *height_out)
|
|
||||||
{
|
{
|
||||||
SDL_Surface *temp = NULL;
|
SDL_Surface *temp = NULL;
|
||||||
SDL_Texture *texture = NULL;
|
SDL_Texture *texture = NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue