From d89fc32864964fed6197605417bb9b2ec019c8bd Mon Sep 17 00:00:00 2001 From: X123M3-256 Date: Tue, 17 Jan 2017 21:33:24 +0000 Subject: [PATCH] Use get_directory_path instead of dirname() --- src/openrct2/cmdline_sprite.c | 8 +++++--- src/openrct2/platform/posix.c | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/openrct2/cmdline_sprite.c b/src/openrct2/cmdline_sprite.c index 8a47ee1313..b584536322 100644 --- a/src/openrct2/cmdline_sprite.c +++ b/src/openrct2/cmdline_sprite.c @@ -662,6 +662,7 @@ sint32 cmdline_for_sprite(const char **argv, sint32 argc) const char *spriteFilePath = argv[1]; const char *spriteDescriptionPath = argv[2]; + const char* directoryPath = path_get_directory(argv[1]); json_error_t error; json_t* sprite_list=json_load_file(spriteDescriptionPath, JSON_REJECT_DUPLICATES, &error); @@ -707,7 +708,7 @@ sint32 cmdline_for_sprite(const char **argv, sint32 argc) //Resolve absolute sprite path - char* imagePath=platform_get_absolute_path(json_string_value(path),spriteDescriptionPath); + char* imagePath=platform_get_absolute_path(json_string_value(path),directoryPath); rct_g1_element spriteElement; uint8 *buffer; @@ -717,7 +718,7 @@ sint32 cmdline_for_sprite(const char **argv, sint32 argc) json_decref(sprite_list); return -1; } - + free(imagePath); if (!sprite_file_open(spriteFilePath)) { fprintf(stderr, "Unable to open sprite file: %s\nCanceling\n", spriteFilePath); @@ -751,7 +752,8 @@ sint32 cmdline_for_sprite(const char **argv, sint32 argc) } json_decref(sprite_list); - + free(directoryPath); + fprintf(stdout, "Finished\n"); return 1; } else { diff --git a/src/openrct2/platform/posix.c b/src/openrct2/platform/posix.c index 775cb6925d..42025fcdc2 100644 --- a/src/openrct2/platform/posix.c +++ b/src/openrct2/platform/posix.c @@ -265,12 +265,12 @@ bool platform_directory_delete(const utf8 *path) char* platform_get_absolute_path(const char* relative_path,const char* base_path) { char path[MAX_PATH]; - - //This is to get around the fact that dirname() doesn't take a const char* - char base_path_copy[MAX_PATH]; - safe_strcpy(base_path_copy,base_path,MAX_PATH); - - snprintf(path,MAX_PATH,"%s/%s",dirname(base_path_copy),relative_path); + + if(base_path!=NULL) { + snprintf(path,MAX_PATH,"%s/%s",base_path,relative_path); + } else { + safe_strcpy(path,base_path,MAX_PATH); + } return realpath(path,NULL); }