Wiki Page Content

Revision 1 as of 2013-10-22 17:42:14

Clear message

DRAFT

SDL_GetBasePath

Use this function to get the directory where the application was run from. This is where the application data directory is.

Syntax

char *SDL_GetBasePath(void)

Return Value

Returns the an absolute path in UTF-8 encoding do the application data directory. NULL will be returned on error or when the platform doesn't implement this functionality, call SDL_GetError() for more information.

The return path will be gauranteed to end with a path separator ('\' on Windows, '/' most other platforms)

The pointer returned is owned by you. Please call SDL_free on the pointer when you are done with it.

Code Examples

char *data_path = NULL;

int InitializeDataPath() {
    char *base_path = SDL_GetBasePath();
    if (base_path) {
        data_path = SDL_strdup(base_path);
        SDL_free(base_path);
    } else {
        data_path = SDL_strdup("./");
    }
}

Remarks

This is not necessarily a fast call, though, so you should call this once near startup and save the string if you need it.


CategoryAPI, CategoryFilesystem

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit