SDL Wiki
(This is the documentation for SDL3, which is under heavy development and the API is changing! SDL2 is the current stable version!)


Use this function to create a new SDL_IOStream structure for reading from and/or writing to a named file.

Header File

Defined in <SDL3/SDL_iostream.h>


SDL_IOStream* SDL_IOFromFile(const char *file, const char *mode);

Function Parameters

const char * file a UTF-8 string representing the filename to open.
const char * mode an ASCII string representing the mode to be used for opening the file.

Return Value

(SDL_IOStream *) Returns a pointer to the SDL_IOStream structure that is created, or NULL on failure; call SDL_GetError() for more information.


The mode string is treated roughly the same as in a call to the C library's fopen(), even if SDL doesn't happen to use fopen() behind the scenes.

Available mode strings:

NOTE: In order to open a file as a binary file, a "b" character has to be included in the mode string. This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+"). Additional characters may follow the sequence, although they should have no effect. For example, "t" is sometimes appended to make explicit the file is a text file.

This function supports Unicode filenames, but they must be encoded in UTF-8 format, regardless of the underlying operating system.

In Android, SDL_IOFromFile() can be used to open content:// URIs. As a fallback, SDL_IOFromFile() will transparently open a matching filename in the app's assets.

Closing the SDL_IOStream will close SDL's internal file handle.

The following properties may be set at creation time by SDL:


This function is available since SDL 3.0.0.

See Also

CategoryAPI, CategoryAPIFunction, CategoryIOStream

[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.