| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any damages |
| 7 | arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any purpose, |
| 10 | including commercial applications, and to alter it and redistribute it |
| 11 | freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must not |
| 14 | claim that you wrote the original software. If you use this software |
| 15 | in a product, an acknowledgment in the product documentation would be |
| 16 | appreciated but is not required. |
| 17 | 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | misrepresented as being the original software. |
| 19 | 3. This notice may not be removed or altered from any source distribution. |
| 20 | */ |
| 21 | |
| 22 | /* WIKI CATEGORY: IOStream */ |
| 23 | |
| 24 | /** |
| 25 | * # CategoryIOStream |
| 26 | * |
| 27 | * SDL provides an abstract interface for reading and writing data streams. It |
| 28 | * offers implementations for files, memory, etc, and the app can provide |
| 29 | * their own implementations, too. |
| 30 | * |
| 31 | * SDL_IOStream is not related to the standard C++ iostream class, other than |
| 32 | * both are abstract interfaces to read/write data. |
| 33 | */ |
| 34 | |
| 35 | #ifndef SDL_iostream_h_ |
| 36 | #define SDL_iostream_h_ |
| 37 | |
| 38 | #include <SDL3/SDL_stdinc.h> |
| 39 | #include <SDL3/SDL_error.h> |
| 40 | #include <SDL3/SDL_properties.h> |
| 41 | |
| 42 | #include <SDL3/SDL_begin_code.h> |
| 43 | /* Set up for C function definitions, even when using C++ */ |
| 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | /** |
| 49 | * SDL_IOStream status, set by a read or write operation. |
| 50 | * |
| 51 | * \since This enum is available since SDL 3.2.0. |
| 52 | */ |
| 53 | typedef enum SDL_IOStatus |
| 54 | { |
| 55 | SDL_IO_STATUS_READY, /**< Everything is ready (no errors and not EOF). */ |
| 56 | SDL_IO_STATUS_ERROR, /**< Read or write I/O error */ |
| 57 | SDL_IO_STATUS_EOF, /**< End of file */ |
| 58 | SDL_IO_STATUS_NOT_READY, /**< Non blocking I/O, not ready */ |
| 59 | SDL_IO_STATUS_READONLY, /**< Tried to write a read-only buffer */ |
| 60 | SDL_IO_STATUS_WRITEONLY /**< Tried to read a write-only buffer */ |
| 61 | } SDL_IOStatus; |
| 62 | |
| 63 | /** |
| 64 | * Possible `whence` values for SDL_IOStream seeking. |
| 65 | * |
| 66 | * These map to the same "whence" concept that `fseek` or `lseek` use in the |
| 67 | * standard C runtime. |
| 68 | * |
| 69 | * \since This enum is available since SDL 3.2.0. |
| 70 | */ |
| 71 | typedef enum SDL_IOWhence |
| 72 | { |
| 73 | SDL_IO_SEEK_SET, /**< Seek from the beginning of data */ |
| 74 | SDL_IO_SEEK_CUR, /**< Seek relative to current read point */ |
| 75 | SDL_IO_SEEK_END /**< Seek relative to the end of data */ |
| 76 | } SDL_IOWhence; |
| 77 | |
| 78 | /** |
| 79 | * The function pointers that drive an SDL_IOStream. |
| 80 | * |
| 81 | * Applications can provide this struct to SDL_OpenIO() to create their own |
| 82 | * implementation of SDL_IOStream. This is not necessarily required, as SDL |
| 83 | * already offers several common types of I/O streams, via functions like |
| 84 | * SDL_IOFromFile() and SDL_IOFromMem(). |
| 85 | * |
| 86 | * This structure should be initialized using SDL_INIT_INTERFACE() |
| 87 | * |
| 88 | * \since This struct is available since SDL 3.2.0. |
| 89 | * |
| 90 | * \sa SDL_INIT_INTERFACE |
| 91 | */ |
| 92 | typedef struct SDL_IOStreamInterface |
| 93 | { |
| 94 | /* The version of this interface */ |
| 95 | Uint32 version; |
| 96 | |
| 97 | /** |
| 98 | * Return the number of bytes in this SDL_IOStream |
| 99 | * |
| 100 | * \return the total size of the data stream, or -1 on error. |
| 101 | */ |
| 102 | Sint64 (SDLCALL *size)(void *userdata); |
| 103 | |
| 104 | /** |
| 105 | * Seek to `offset` relative to `whence`, one of stdio's whence values: |
| 106 | * SDL_IO_SEEK_SET, SDL_IO_SEEK_CUR, SDL_IO_SEEK_END |
| 107 | * |
| 108 | * \return the final offset in the data stream, or -1 on error. |
| 109 | */ |
| 110 | Sint64 (SDLCALL *seek)(void *userdata, Sint64 offset, SDL_IOWhence whence); |
| 111 | |
| 112 | /** |
| 113 | * Read up to `size` bytes from the data stream to the area pointed |
| 114 | * at by `ptr`. |
| 115 | * |
| 116 | * On an incomplete read, you should set `*status` to a value from the |
| 117 | * SDL_IOStatus enum. You do not have to explicitly set this on |
| 118 | * a complete, successful read. |
| 119 | * |
| 120 | * \return the number of bytes read |
| 121 | */ |
| 122 | size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_IOStatus *status); |
| 123 | |
| 124 | /** |
| 125 | * Write exactly `size` bytes from the area pointed at by `ptr` |
| 126 | * to data stream. |
| 127 | * |
| 128 | * On an incomplete write, you should set `*status` to a value from the |
| 129 | * SDL_IOStatus enum. You do not have to explicitly set this on |
| 130 | * a complete, successful write. |
| 131 | * |
| 132 | * \return the number of bytes written |
| 133 | */ |
| 134 | size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_IOStatus *status); |
| 135 | |
| 136 | /** |
| 137 | * If the stream is buffering, make sure the data is written out. |
| 138 | * |
| 139 | * On failure, you should set `*status` to a value from the |
| 140 | * SDL_IOStatus enum. You do not have to explicitly set this on |
| 141 | * a successful flush. |
| 142 | * |
| 143 | * \return true if successful or false on write error when flushing data. |
| 144 | */ |
| 145 | bool (SDLCALL *flush)(void *userdata, SDL_IOStatus *status); |
| 146 | |
| 147 | /** |
| 148 | * Close and free any allocated resources. |
| 149 | * |
| 150 | * This does not guarantee file writes will sync to physical media; they |
| 151 | * can be in the system's file cache, waiting to go to disk. |
| 152 | * |
| 153 | * The SDL_IOStream is still destroyed even if this fails, so clean up anything |
| 154 | * even if flushing buffers, etc, returns an error. |
| 155 | * |
| 156 | * \return true if successful or false on write error when flushing data. |
| 157 | */ |
| 158 | bool (SDLCALL *close)(void *userdata); |
| 159 | |
| 160 | } SDL_IOStreamInterface; |
| 161 | |
| 162 | /* Check the size of SDL_IOStreamInterface |
| 163 | * |
| 164 | * If this assert fails, either the compiler is padding to an unexpected size, |
| 165 | * or the interface has been updated and this should be updated to match and |
| 166 | * the code using this interface should be updated to handle the old version. |
| 167 | */ |
| 168 | SDL_COMPILE_TIME_ASSERT(SDL_IOStreamInterface_SIZE, |
| 169 | (sizeof(void *) == 4 && sizeof(SDL_IOStreamInterface) == 28) || |
| 170 | (sizeof(void *) == 8 && sizeof(SDL_IOStreamInterface) == 56)); |
| 171 | |
| 172 | /** |
| 173 | * The read/write operation structure. |
| 174 | * |
| 175 | * This operates as an opaque handle. There are several APIs to create various |
| 176 | * types of I/O streams, or an app can supply an SDL_IOStreamInterface to |
| 177 | * SDL_OpenIO() to provide their own stream implementation behind this |
| 178 | * struct's abstract interface. |
| 179 | * |
| 180 | * \since This struct is available since SDL 3.2.0. |
| 181 | */ |
| 182 | typedef struct SDL_IOStream SDL_IOStream; |
| 183 | |
| 184 | |
| 185 | /** |
| 186 | * \name IOFrom functions |
| 187 | * |
| 188 | * Functions to create SDL_IOStream structures from various data streams. |
| 189 | */ |
| 190 | /* @{ */ |
| 191 | |
| 192 | /** |
| 193 | * Use this function to create a new SDL_IOStream structure for reading from |
| 194 | * and/or writing to a named file. |
| 195 | * |
| 196 | * The `mode` string is treated roughly the same as in a call to the C |
| 197 | * library's fopen(), even if SDL doesn't happen to use fopen() behind the |
| 198 | * scenes. |
| 199 | * |
| 200 | * Available `mode` strings: |
| 201 | * |
| 202 | * - "r": Open a file for reading. The file must exist. |
| 203 | * - "w": Create an empty file for writing. If a file with the same name |
| 204 | * already exists its content is erased and the file is treated as a new |
| 205 | * empty file. |
| 206 | * - "a": Append to a file. Writing operations append data at the end of the |
| 207 | * file. The file is created if it does not exist. |
| 208 | * - "r+": Open a file for update both reading and writing. The file must |
| 209 | * exist. |
| 210 | * - "w+": Create an empty file for both reading and writing. If a file with |
| 211 | * the same name already exists its content is erased and the file is |
| 212 | * treated as a new empty file. |
| 213 | * - "a+": Open a file for reading and appending. All writing operations are |
| 214 | * performed at the end of the file, protecting the previous content to be |
| 215 | * overwritten. You can reposition (fseek, rewind) the internal pointer to |
| 216 | * anywhere in the file for reading, but writing operations will move it |
| 217 | * back to the end of file. The file is created if it does not exist. |
| 218 | * |
| 219 | * **NOTE**: In order to open a file as a binary file, a "b" character has to |
| 220 | * be included in the `mode` string. This additional "b" character can either |
| 221 | * be appended at the end of the string (thus making the following compound |
| 222 | * modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the |
| 223 | * letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+"). |
| 224 | * Additional characters may follow the sequence, although they should have no |
| 225 | * effect. For example, "t" is sometimes appended to make explicit the file is |
| 226 | * a text file. |
| 227 | * |
| 228 | * This function supports Unicode filenames, but they must be encoded in UTF-8 |
| 229 | * format, regardless of the underlying operating system. |
| 230 | * |
| 231 | * In Android, SDL_IOFromFile() can be used to open content:// URIs. As a |
| 232 | * fallback, SDL_IOFromFile() will transparently open a matching filename in |
| 233 | * the app's `assets`. |
| 234 | * |
| 235 | * Closing the SDL_IOStream will close SDL's internal file handle. |
| 236 | * |
| 237 | * The following properties may be set at creation time by SDL: |
| 238 | * |
| 239 | * - `SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER`: a pointer, that can be cast |
| 240 | * to a win32 `HANDLE`, that this SDL_IOStream is using to access the |
| 241 | * filesystem. If the program isn't running on Windows, or SDL used some |
| 242 | * other method to access the filesystem, this property will not be set. |
| 243 | * - `SDL_PROP_IOSTREAM_STDIO_FILE_POINTER`: a pointer, that can be cast to a |
| 244 | * stdio `FILE *`, that this SDL_IOStream is using to access the filesystem. |
| 245 | * If SDL used some other method to access the filesystem, this property |
| 246 | * will not be set. PLEASE NOTE that if SDL is using a different C runtime |
| 247 | * than your app, trying to use this pointer will almost certainly result in |
| 248 | * a crash! This is mostly a problem on Windows; make sure you build SDL and |
| 249 | * your app with the same compiler and settings to avoid it. |
| 250 | * - `SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER`: a file descriptor that this |
| 251 | * SDL_IOStream is using to access the filesystem. |
| 252 | * - `SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER`: a pointer, that can be cast |
| 253 | * to an Android NDK `AAsset *`, that this SDL_IOStream is using to access |
| 254 | * the filesystem. If SDL used some other method to access the filesystem, |
| 255 | * this property will not be set. |
| 256 | * |
| 257 | * \param file a UTF-8 string representing the filename to open. |
| 258 | * \param mode an ASCII string representing the mode to be used for opening |
| 259 | * the file. |
| 260 | * \returns a pointer to the SDL_IOStream structure that is created or NULL on |
| 261 | * failure; call SDL_GetError() for more information. |
| 262 | * |
| 263 | * \threadsafety This function is not thread safe. |
| 264 | * |
| 265 | * \since This function is available since SDL 3.2.0. |
| 266 | * |
| 267 | * \sa SDL_CloseIO |
| 268 | * \sa SDL_FlushIO |
| 269 | * \sa SDL_ReadIO |
| 270 | * \sa SDL_SeekIO |
| 271 | * \sa SDL_TellIO |
| 272 | * \sa SDL_WriteIO |
| 273 | */ |
| 274 | extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromFile(const char *file, const char *mode); |
| 275 | |
| 276 | #define SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER "SDL.iostream.windows.handle" |
| 277 | #define SDL_PROP_IOSTREAM_STDIO_FILE_POINTER "SDL.iostream.stdio.file" |
| 278 | #define SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER "SDL.iostream.file_descriptor" |
| 279 | #define SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER "SDL.iostream.android.aasset" |
| 280 | |
| 281 | /** |
| 282 | * Use this function to prepare a read-write memory buffer for use with |
| 283 | * SDL_IOStream. |
| 284 | * |
| 285 | * This function sets up an SDL_IOStream struct based on a memory area of a |
| 286 | * certain size, for both read and write access. |
| 287 | * |
| 288 | * This memory buffer is not copied by the SDL_IOStream; the pointer you |
| 289 | * provide must remain valid until you close the stream. Closing the stream |
| 290 | * will not free the original buffer. |
| 291 | * |
| 292 | * If you need to make sure the SDL_IOStream never writes to the memory |
| 293 | * buffer, you should use SDL_IOFromConstMem() with a read-only buffer of |
| 294 | * memory instead. |
| 295 | * |
| 296 | * The following properties will be set at creation time by SDL: |
| 297 | * |
| 298 | * - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that |
| 299 | * was passed to this function. |
| 300 | * - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter |
| 301 | * that was passed to this function. |
| 302 | * |
| 303 | * \param mem a pointer to a buffer to feed an SDL_IOStream stream. |
| 304 | * \param size the buffer size, in bytes. |
| 305 | * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call |
| 306 | * SDL_GetError() for more information. |
| 307 | * |
| 308 | * \threadsafety It is safe to call this function from any thread. |
| 309 | * |
| 310 | * \since This function is available since SDL 3.2.0. |
| 311 | * |
| 312 | * \sa SDL_IOFromConstMem |
| 313 | * \sa SDL_CloseIO |
| 314 | * \sa SDL_FlushIO |
| 315 | * \sa SDL_ReadIO |
| 316 | * \sa SDL_SeekIO |
| 317 | * \sa SDL_TellIO |
| 318 | * \sa SDL_WriteIO |
| 319 | */ |
| 320 | extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromMem(void *mem, size_t size); |
| 321 | |
| 322 | #define SDL_PROP_IOSTREAM_MEMORY_POINTER "SDL.iostream.memory.base" |
| 323 | #define SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER "SDL.iostream.memory.size" |
| 324 | |
| 325 | /** |
| 326 | * Use this function to prepare a read-only memory buffer for use with |
| 327 | * SDL_IOStream. |
| 328 | * |
| 329 | * This function sets up an SDL_IOStream struct based on a memory area of a |
| 330 | * certain size. It assumes the memory area is not writable. |
| 331 | * |
| 332 | * Attempting to write to this SDL_IOStream stream will report an error |
| 333 | * without writing to the memory buffer. |
| 334 | * |
| 335 | * This memory buffer is not copied by the SDL_IOStream; the pointer you |
| 336 | * provide must remain valid until you close the stream. Closing the stream |
| 337 | * will not free the original buffer. |
| 338 | * |
| 339 | * If you need to write to a memory buffer, you should use SDL_IOFromMem() |
| 340 | * with a writable buffer of memory instead. |
| 341 | * |
| 342 | * The following properties will be set at creation time by SDL: |
| 343 | * |
| 344 | * - `SDL_PROP_IOSTREAM_MEMORY_POINTER`: this will be the `mem` parameter that |
| 345 | * was passed to this function. |
| 346 | * - `SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER`: this will be the `size` parameter |
| 347 | * that was passed to this function. |
| 348 | * |
| 349 | * \param mem a pointer to a read-only buffer to feed an SDL_IOStream stream. |
| 350 | * \param size the buffer size, in bytes. |
| 351 | * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call |
| 352 | * SDL_GetError() for more information. |
| 353 | * |
| 354 | * \threadsafety It is safe to call this function from any thread. |
| 355 | * |
| 356 | * \since This function is available since SDL 3.2.0. |
| 357 | * |
| 358 | * \sa SDL_IOFromMem |
| 359 | * \sa SDL_CloseIO |
| 360 | * \sa SDL_ReadIO |
| 361 | * \sa SDL_SeekIO |
| 362 | * \sa SDL_TellIO |
| 363 | */ |
| 364 | extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromConstMem(const void *mem, size_t size); |
| 365 | |
| 366 | /** |
| 367 | * Use this function to create an SDL_IOStream that is backed by dynamically |
| 368 | * allocated memory. |
| 369 | * |
| 370 | * This supports the following properties to provide access to the memory and |
| 371 | * control over allocations: |
| 372 | * |
| 373 | * - `SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER`: a pointer to the internal |
| 374 | * memory of the stream. This can be set to NULL to transfer ownership of |
| 375 | * the memory to the application, which should free the memory with |
| 376 | * SDL_free(). If this is done, the next operation on the stream must be |
| 377 | * SDL_CloseIO(). |
| 378 | * - `SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER`: memory will be allocated in |
| 379 | * multiples of this size, defaulting to 1024. |
| 380 | * |
| 381 | * \returns a pointer to a new SDL_IOStream structure or NULL on failure; call |
| 382 | * SDL_GetError() for more information. |
| 383 | * |
| 384 | * \threadsafety It is safe to call this function from any thread. |
| 385 | * |
| 386 | * \since This function is available since SDL 3.2.0. |
| 387 | * |
| 388 | * \sa SDL_CloseIO |
| 389 | * \sa SDL_ReadIO |
| 390 | * \sa SDL_SeekIO |
| 391 | * \sa SDL_TellIO |
| 392 | * \sa SDL_WriteIO |
| 393 | */ |
| 394 | extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_IOFromDynamicMem(void); |
| 395 | |
| 396 | #define SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER "SDL.iostream.dynamic.memory" |
| 397 | #define SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER "SDL.iostream.dynamic.chunksize" |
| 398 | |
| 399 | /* @} *//* IOFrom functions */ |
| 400 | |
| 401 | |
| 402 | /** |
| 403 | * Create a custom SDL_IOStream. |
| 404 | * |
| 405 | * Applications do not need to use this function unless they are providing |
| 406 | * their own SDL_IOStream implementation. If you just need an SDL_IOStream to |
| 407 | * read/write a common data source, you should use the built-in |
| 408 | * implementations in SDL, like SDL_IOFromFile() or SDL_IOFromMem(), etc. |
| 409 | * |
| 410 | * This function makes a copy of `iface` and the caller does not need to keep |
| 411 | * it around after this call. |
| 412 | * |
| 413 | * \param iface the interface that implements this SDL_IOStream, initialized |
| 414 | * using SDL_INIT_INTERFACE(). |
| 415 | * \param userdata the pointer that will be passed to the interface functions. |
| 416 | * \returns a pointer to the allocated memory on success or NULL on failure; |
| 417 | * call SDL_GetError() for more information. |
| 418 | * |
| 419 | * \threadsafety It is safe to call this function from any thread. |
| 420 | * |
| 421 | * \since This function is available since SDL 3.2.0. |
| 422 | * |
| 423 | * \sa SDL_CloseIO |
| 424 | * \sa SDL_INIT_INTERFACE |
| 425 | * \sa SDL_IOFromConstMem |
| 426 | * \sa SDL_IOFromFile |
| 427 | * \sa SDL_IOFromMem |
| 428 | */ |
| 429 | extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata); |
| 430 | |
| 431 | /** |
| 432 | * Close and free an allocated SDL_IOStream structure. |
| 433 | * |
| 434 | * SDL_CloseIO() closes and cleans up the SDL_IOStream stream. It releases any |
| 435 | * resources used by the stream and frees the SDL_IOStream itself. This |
| 436 | * returns true on success, or false if the stream failed to flush to its |
| 437 | * output (e.g. to disk). |
| 438 | * |
| 439 | * Note that if this fails to flush the stream for any reason, this function |
| 440 | * reports an error, but the SDL_IOStream is still invalid once this function |
| 441 | * returns. |
| 442 | * |
| 443 | * This call flushes any buffered writes to the operating system, but there |
| 444 | * are no guarantees that those writes have gone to physical media; they might |
| 445 | * be in the OS's file cache, waiting to go to disk later. If it's absolutely |
| 446 | * crucial that writes go to disk immediately, so they are definitely stored |
| 447 | * even if the power fails before the file cache would have caught up, one |
| 448 | * should call SDL_FlushIO() before closing. Note that flushing takes time and |
| 449 | * makes the system and your app operate less efficiently, so do so sparingly. |
| 450 | * |
| 451 | * \param context SDL_IOStream structure to close. |
| 452 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 453 | * information. |
| 454 | * |
| 455 | * \threadsafety This function is not thread safe. |
| 456 | * |
| 457 | * \since This function is available since SDL 3.2.0. |
| 458 | * |
| 459 | * \sa SDL_OpenIO |
| 460 | */ |
| 461 | extern SDL_DECLSPEC bool SDLCALL SDL_CloseIO(SDL_IOStream *context); |
| 462 | |
| 463 | /** |
| 464 | * Get the properties associated with an SDL_IOStream. |
| 465 | * |
| 466 | * \param context a pointer to an SDL_IOStream structure. |
| 467 | * \returns a valid property ID on success or 0 on failure; call |
| 468 | * SDL_GetError() for more information. |
| 469 | * |
| 470 | * \threadsafety This function is not thread safe. |
| 471 | * |
| 472 | * \since This function is available since SDL 3.2.0. |
| 473 | */ |
| 474 | extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetIOProperties(SDL_IOStream *context); |
| 475 | |
| 476 | /** |
| 477 | * Query the stream status of an SDL_IOStream. |
| 478 | * |
| 479 | * This information can be useful to decide if a short read or write was due |
| 480 | * to an error, an EOF, or a non-blocking operation that isn't yet ready to |
| 481 | * complete. |
| 482 | * |
| 483 | * An SDL_IOStream's status is only expected to change after a SDL_ReadIO or |
| 484 | * SDL_WriteIO call; don't expect it to change if you just call this query |
| 485 | * function in a tight loop. |
| 486 | * |
| 487 | * \param context the SDL_IOStream to query. |
| 488 | * \returns an SDL_IOStatus enum with the current state. |
| 489 | * |
| 490 | * \threadsafety This function is not thread safe. |
| 491 | * |
| 492 | * \since This function is available since SDL 3.2.0. |
| 493 | */ |
| 494 | extern SDL_DECLSPEC SDL_IOStatus SDLCALL SDL_GetIOStatus(SDL_IOStream *context); |
| 495 | |
| 496 | /** |
| 497 | * Use this function to get the size of the data stream in an SDL_IOStream. |
| 498 | * |
| 499 | * \param context the SDL_IOStream to get the size of the data stream from. |
| 500 | * \returns the size of the data stream in the SDL_IOStream on success or a |
| 501 | * negative error code on failure; call SDL_GetError() for more |
| 502 | * information. |
| 503 | * |
| 504 | * \threadsafety This function is not thread safe. |
| 505 | * |
| 506 | * \since This function is available since SDL 3.2.0. |
| 507 | */ |
| 508 | extern SDL_DECLSPEC Sint64 SDLCALL SDL_GetIOSize(SDL_IOStream *context); |
| 509 | |
| 510 | /** |
| 511 | * Seek within an SDL_IOStream data stream. |
| 512 | * |
| 513 | * This function seeks to byte `offset`, relative to `whence`. |
| 514 | * |
| 515 | * `whence` may be any of the following values: |
| 516 | * |
| 517 | * - `SDL_IO_SEEK_SET`: seek from the beginning of data |
| 518 | * - `SDL_IO_SEEK_CUR`: seek relative to current read point |
| 519 | * - `SDL_IO_SEEK_END`: seek relative to the end of data |
| 520 | * |
| 521 | * If this stream can not seek, it will return -1. |
| 522 | * |
| 523 | * \param context a pointer to an SDL_IOStream structure. |
| 524 | * \param offset an offset in bytes, relative to `whence` location; can be |
| 525 | * negative. |
| 526 | * \param whence any of `SDL_IO_SEEK_SET`, `SDL_IO_SEEK_CUR`, |
| 527 | * `SDL_IO_SEEK_END`. |
| 528 | * \returns the final offset in the data stream after the seek or -1 on |
| 529 | * failure; call SDL_GetError() for more information. |
| 530 | * |
| 531 | * \threadsafety This function is not thread safe. |
| 532 | * |
| 533 | * \since This function is available since SDL 3.2.0. |
| 534 | * |
| 535 | * \sa SDL_TellIO |
| 536 | */ |
| 537 | extern SDL_DECLSPEC Sint64 SDLCALL SDL_SeekIO(SDL_IOStream *context, Sint64 offset, SDL_IOWhence whence); |
| 538 | |
| 539 | /** |
| 540 | * Determine the current read/write offset in an SDL_IOStream data stream. |
| 541 | * |
| 542 | * SDL_TellIO is actually a wrapper function that calls the SDL_IOStream's |
| 543 | * `seek` method, with an offset of 0 bytes from `SDL_IO_SEEK_CUR`, to |
| 544 | * simplify application development. |
| 545 | * |
| 546 | * \param context an SDL_IOStream data stream object from which to get the |
| 547 | * current offset. |
| 548 | * \returns the current offset in the stream, or -1 if the information can not |
| 549 | * be determined. |
| 550 | * |
| 551 | * \threadsafety This function is not thread safe. |
| 552 | * |
| 553 | * \since This function is available since SDL 3.2.0. |
| 554 | * |
| 555 | * \sa SDL_SeekIO |
| 556 | */ |
| 557 | extern SDL_DECLSPEC Sint64 SDLCALL SDL_TellIO(SDL_IOStream *context); |
| 558 | |
| 559 | /** |
| 560 | * Read from a data source. |
| 561 | * |
| 562 | * This function reads up `size` bytes from the data source to the area |
| 563 | * pointed at by `ptr`. This function may read less bytes than requested. |
| 564 | * |
| 565 | * This function will return zero when the data stream is completely read, and |
| 566 | * SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If zero is returned and |
| 567 | * the stream is not at EOF, SDL_GetIOStatus() will return a different error |
| 568 | * value and SDL_GetError() will offer a human-readable message. |
| 569 | * |
| 570 | * \param context a pointer to an SDL_IOStream structure. |
| 571 | * \param ptr a pointer to a buffer to read data into. |
| 572 | * \param size the number of bytes to read from the data source. |
| 573 | * \returns the number of bytes read, or 0 on end of file or other failure; |
| 574 | * call SDL_GetError() for more information. |
| 575 | * |
| 576 | * \threadsafety This function is not thread safe. |
| 577 | * |
| 578 | * \since This function is available since SDL 3.2.0. |
| 579 | * |
| 580 | * \sa SDL_WriteIO |
| 581 | * \sa SDL_GetIOStatus |
| 582 | */ |
| 583 | extern SDL_DECLSPEC size_t SDLCALL SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size); |
| 584 | |
| 585 | /** |
| 586 | * Write to an SDL_IOStream data stream. |
| 587 | * |
| 588 | * This function writes exactly `size` bytes from the area pointed at by `ptr` |
| 589 | * to the stream. If this fails for any reason, it'll return less than `size` |
| 590 | * to demonstrate how far the write progressed. On success, it returns `size`. |
| 591 | * |
| 592 | * On error, this function still attempts to write as much as possible, so it |
| 593 | * might return a positive value less than the requested write size. |
| 594 | * |
| 595 | * The caller can use SDL_GetIOStatus() to determine if the problem is |
| 596 | * recoverable, such as a non-blocking write that can simply be retried later, |
| 597 | * or a fatal error. |
| 598 | * |
| 599 | * \param context a pointer to an SDL_IOStream structure. |
| 600 | * \param ptr a pointer to a buffer containing data to write. |
| 601 | * \param size the number of bytes to write. |
| 602 | * \returns the number of bytes written, which will be less than `size` on |
| 603 | * failure; call SDL_GetError() for more information. |
| 604 | * |
| 605 | * \threadsafety This function is not thread safe. |
| 606 | * |
| 607 | * \since This function is available since SDL 3.2.0. |
| 608 | * |
| 609 | * \sa SDL_IOprintf |
| 610 | * \sa SDL_ReadIO |
| 611 | * \sa SDL_SeekIO |
| 612 | * \sa SDL_FlushIO |
| 613 | * \sa SDL_GetIOStatus |
| 614 | */ |
| 615 | extern SDL_DECLSPEC size_t SDLCALL SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size); |
| 616 | |
| 617 | /** |
| 618 | * Print to an SDL_IOStream data stream. |
| 619 | * |
| 620 | * This function does formatted printing to the stream. |
| 621 | * |
| 622 | * \param context a pointer to an SDL_IOStream structure. |
| 623 | * \param fmt a printf() style format string. |
| 624 | * \param ... additional parameters matching % tokens in the `fmt` string, if |
| 625 | * any. |
| 626 | * \returns the number of bytes written or 0 on failure; call SDL_GetError() |
| 627 | * for more information. |
| 628 | * |
| 629 | * \threadsafety This function is not thread safe. |
| 630 | * |
| 631 | * \since This function is available since SDL 3.2.0. |
| 632 | * |
| 633 | * \sa SDL_IOvprintf |
| 634 | * \sa SDL_WriteIO |
| 635 | */ |
| 636 | extern SDL_DECLSPEC size_t SDLCALL SDL_IOprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2); |
| 637 | |
| 638 | /** |
| 639 | * Print to an SDL_IOStream data stream. |
| 640 | * |
| 641 | * This function does formatted printing to the stream. |
| 642 | * |
| 643 | * \param context a pointer to an SDL_IOStream structure. |
| 644 | * \param fmt a printf() style format string. |
| 645 | * \param ap a variable argument list. |
| 646 | * \returns the number of bytes written or 0 on failure; call SDL_GetError() |
| 647 | * for more information. |
| 648 | * |
| 649 | * \threadsafety This function is not thread safe. |
| 650 | * |
| 651 | * \since This function is available since SDL 3.2.0. |
| 652 | * |
| 653 | * \sa SDL_IOprintf |
| 654 | * \sa SDL_WriteIO |
| 655 | */ |
| 656 | extern SDL_DECLSPEC size_t SDLCALL SDL_IOvprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2); |
| 657 | |
| 658 | /** |
| 659 | * Flush any buffered data in the stream. |
| 660 | * |
| 661 | * This function makes sure that any buffered data is written to the stream. |
| 662 | * Normally this isn't necessary but if the stream is a pipe or socket it |
| 663 | * guarantees that any pending data is sent. |
| 664 | * |
| 665 | * \param context SDL_IOStream structure to flush. |
| 666 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 667 | * information. |
| 668 | * |
| 669 | * \threadsafety This function is not thread safe. |
| 670 | * |
| 671 | * \since This function is available since SDL 3.2.0. |
| 672 | * |
| 673 | * \sa SDL_OpenIO |
| 674 | * \sa SDL_WriteIO |
| 675 | */ |
| 676 | extern SDL_DECLSPEC bool SDLCALL SDL_FlushIO(SDL_IOStream *context); |
| 677 | |
| 678 | /** |
| 679 | * Load all the data from an SDL data stream. |
| 680 | * |
| 681 | * The data is allocated with a zero byte at the end (null terminated) for |
| 682 | * convenience. This extra byte is not included in the value reported via |
| 683 | * `datasize`. |
| 684 | * |
| 685 | * The data should be freed with SDL_free(). |
| 686 | * |
| 687 | * \param src the SDL_IOStream to read all available data from. |
| 688 | * \param datasize a pointer filled in with the number of bytes read, may be |
| 689 | * NULL. |
| 690 | * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even |
| 691 | * in the case of an error. |
| 692 | * \returns the data or NULL on failure; call SDL_GetError() for more |
| 693 | * information. |
| 694 | * |
| 695 | * \threadsafety This function is not thread safe. |
| 696 | * |
| 697 | * \since This function is available since SDL 3.2.0. |
| 698 | * |
| 699 | * \sa SDL_LoadFile |
| 700 | * \sa SDL_SaveFile_IO |
| 701 | */ |
| 702 | extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile_IO(SDL_IOStream *src, size_t *datasize, bool closeio); |
| 703 | |
| 704 | /** |
| 705 | * Load all the data from a file path. |
| 706 | * |
| 707 | * The data is allocated with a zero byte at the end (null terminated) for |
| 708 | * convenience. This extra byte is not included in the value reported via |
| 709 | * `datasize`. |
| 710 | * |
| 711 | * The data should be freed with SDL_free(). |
| 712 | * |
| 713 | * \param file the path to read all available data from. |
| 714 | * \param datasize if not NULL, will store the number of bytes read. |
| 715 | * \returns the data or NULL on failure; call SDL_GetError() for more |
| 716 | * information. |
| 717 | * |
| 718 | * \threadsafety This function is not thread safe. |
| 719 | * |
| 720 | * \since This function is available since SDL 3.2.0. |
| 721 | * |
| 722 | * \sa SDL_LoadFile_IO |
| 723 | * \sa SDL_SaveFile |
| 724 | */ |
| 725 | extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile(const char *file, size_t *datasize); |
| 726 | |
| 727 | /** |
| 728 | * Save all the data into an SDL data stream. |
| 729 | * |
| 730 | * \param src the SDL_IOStream to write all data to. |
| 731 | * \param data the data to be written. If datasize is 0, may be NULL or a |
| 732 | * invalid pointer. |
| 733 | * \param datasize the number of bytes to be written. |
| 734 | * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even |
| 735 | * in the case of an error. |
| 736 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 737 | * information. |
| 738 | * |
| 739 | * \threadsafety This function is not thread safe. |
| 740 | * |
| 741 | * \since This function is available since SDL 3.2.0. |
| 742 | * |
| 743 | * \sa SDL_SaveFile |
| 744 | * \sa SDL_LoadFile_IO |
| 745 | */ |
| 746 | extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile_IO(SDL_IOStream *src, const void *data, size_t datasize, bool closeio); |
| 747 | |
| 748 | /** |
| 749 | * Save all the data into a file path. |
| 750 | * |
| 751 | * \param file the path to write all available data into. |
| 752 | * \param data the data to be written. If datasize is 0, may be NULL or a |
| 753 | * invalid pointer. |
| 754 | * \param datasize the number of bytes to be written. |
| 755 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 756 | * information. |
| 757 | * |
| 758 | * \threadsafety This function is not thread safe. |
| 759 | * |
| 760 | * \since This function is available since SDL 3.2.0. |
| 761 | * |
| 762 | * \sa SDL_SaveFile_IO |
| 763 | * \sa SDL_LoadFile |
| 764 | */ |
| 765 | extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile(const char *file, const void *data, size_t datasize); |
| 766 | |
| 767 | /** |
| 768 | * \name Read endian functions |
| 769 | * |
| 770 | * Read an item of the specified endianness and return in native format. |
| 771 | */ |
| 772 | /* @{ */ |
| 773 | |
| 774 | /** |
| 775 | * Use this function to read a byte from an SDL_IOStream. |
| 776 | * |
| 777 | * This function will return false when the data stream is completely read, |
| 778 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 779 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 780 | * error value and SDL_GetError() will offer a human-readable message. |
| 781 | * |
| 782 | * \param src the SDL_IOStream to read from. |
| 783 | * \param value a pointer filled in with the data read. |
| 784 | * \returns true on success or false on failure or EOF; call SDL_GetError() |
| 785 | * for more information. |
| 786 | * |
| 787 | * \threadsafety This function is not thread safe. |
| 788 | * |
| 789 | * \since This function is available since SDL 3.2.0. |
| 790 | */ |
| 791 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU8(SDL_IOStream *src, Uint8 *value); |
| 792 | |
| 793 | /** |
| 794 | * Use this function to read a signed byte from an SDL_IOStream. |
| 795 | * |
| 796 | * This function will return false when the data stream is completely read, |
| 797 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 798 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 799 | * error value and SDL_GetError() will offer a human-readable message. |
| 800 | * |
| 801 | * \param src the SDL_IOStream to read from. |
| 802 | * \param value a pointer filled in with the data read. |
| 803 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 804 | * information. |
| 805 | * |
| 806 | * \threadsafety This function is not thread safe. |
| 807 | * |
| 808 | * \since This function is available since SDL 3.2.0. |
| 809 | */ |
| 810 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS8(SDL_IOStream *src, Sint8 *value); |
| 811 | |
| 812 | /** |
| 813 | * Use this function to read 16 bits of little-endian data from an |
| 814 | * SDL_IOStream and return in native format. |
| 815 | * |
| 816 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 817 | * the native byte order. |
| 818 | * |
| 819 | * This function will return false when the data stream is completely read, |
| 820 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 821 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 822 | * error value and SDL_GetError() will offer a human-readable message. |
| 823 | * |
| 824 | * \param src the stream from which to read data. |
| 825 | * \param value a pointer filled in with the data read. |
| 826 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 827 | * for more information. |
| 828 | * |
| 829 | * \threadsafety This function is not thread safe. |
| 830 | * |
| 831 | * \since This function is available since SDL 3.2.0. |
| 832 | */ |
| 833 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16LE(SDL_IOStream *src, Uint16 *value); |
| 834 | |
| 835 | /** |
| 836 | * Use this function to read 16 bits of little-endian data from an |
| 837 | * SDL_IOStream and return in native format. |
| 838 | * |
| 839 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 840 | * the native byte order. |
| 841 | * |
| 842 | * This function will return false when the data stream is completely read, |
| 843 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 844 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 845 | * error value and SDL_GetError() will offer a human-readable message. |
| 846 | * |
| 847 | * \param src the stream from which to read data. |
| 848 | * \param value a pointer filled in with the data read. |
| 849 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 850 | * for more information. |
| 851 | * |
| 852 | * \threadsafety This function is not thread safe. |
| 853 | * |
| 854 | * \since This function is available since SDL 3.2.0. |
| 855 | */ |
| 856 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16LE(SDL_IOStream *src, Sint16 *value); |
| 857 | |
| 858 | /** |
| 859 | * Use this function to read 16 bits of big-endian data from an SDL_IOStream |
| 860 | * and return in native format. |
| 861 | * |
| 862 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 863 | * the native byte order. |
| 864 | * |
| 865 | * This function will return false when the data stream is completely read, |
| 866 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 867 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 868 | * error value and SDL_GetError() will offer a human-readable message. |
| 869 | * |
| 870 | * \param src the stream from which to read data. |
| 871 | * \param value a pointer filled in with the data read. |
| 872 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 873 | * for more information. |
| 874 | * |
| 875 | * \threadsafety This function is not thread safe. |
| 876 | * |
| 877 | * \since This function is available since SDL 3.2.0. |
| 878 | */ |
| 879 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16BE(SDL_IOStream *src, Uint16 *value); |
| 880 | |
| 881 | /** |
| 882 | * Use this function to read 16 bits of big-endian data from an SDL_IOStream |
| 883 | * and return in native format. |
| 884 | * |
| 885 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 886 | * the native byte order. |
| 887 | * |
| 888 | * This function will return false when the data stream is completely read, |
| 889 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 890 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 891 | * error value and SDL_GetError() will offer a human-readable message. |
| 892 | * |
| 893 | * \param src the stream from which to read data. |
| 894 | * \param value a pointer filled in with the data read. |
| 895 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 896 | * for more information. |
| 897 | * |
| 898 | * \threadsafety This function is not thread safe. |
| 899 | * |
| 900 | * \since This function is available since SDL 3.2.0. |
| 901 | */ |
| 902 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16BE(SDL_IOStream *src, Sint16 *value); |
| 903 | |
| 904 | /** |
| 905 | * Use this function to read 32 bits of little-endian data from an |
| 906 | * SDL_IOStream and return in native format. |
| 907 | * |
| 908 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 909 | * the native byte order. |
| 910 | * |
| 911 | * This function will return false when the data stream is completely read, |
| 912 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 913 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 914 | * error value and SDL_GetError() will offer a human-readable message. |
| 915 | * |
| 916 | * \param src the stream from which to read data. |
| 917 | * \param value a pointer filled in with the data read. |
| 918 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 919 | * for more information. |
| 920 | * |
| 921 | * \threadsafety This function is not thread safe. |
| 922 | * |
| 923 | * \since This function is available since SDL 3.2.0. |
| 924 | */ |
| 925 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32LE(SDL_IOStream *src, Uint32 *value); |
| 926 | |
| 927 | /** |
| 928 | * Use this function to read 32 bits of little-endian data from an |
| 929 | * SDL_IOStream and return in native format. |
| 930 | * |
| 931 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 932 | * the native byte order. |
| 933 | * |
| 934 | * This function will return false when the data stream is completely read, |
| 935 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 936 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 937 | * error value and SDL_GetError() will offer a human-readable message. |
| 938 | * |
| 939 | * \param src the stream from which to read data. |
| 940 | * \param value a pointer filled in with the data read. |
| 941 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 942 | * for more information. |
| 943 | * |
| 944 | * \threadsafety This function is not thread safe. |
| 945 | * |
| 946 | * \since This function is available since SDL 3.2.0. |
| 947 | */ |
| 948 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32LE(SDL_IOStream *src, Sint32 *value); |
| 949 | |
| 950 | /** |
| 951 | * Use this function to read 32 bits of big-endian data from an SDL_IOStream |
| 952 | * and return in native format. |
| 953 | * |
| 954 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 955 | * the native byte order. |
| 956 | * |
| 957 | * This function will return false when the data stream is completely read, |
| 958 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 959 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 960 | * error value and SDL_GetError() will offer a human-readable message. |
| 961 | * |
| 962 | * \param src the stream from which to read data. |
| 963 | * \param value a pointer filled in with the data read. |
| 964 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 965 | * for more information. |
| 966 | * |
| 967 | * \threadsafety This function is not thread safe. |
| 968 | * |
| 969 | * \since This function is available since SDL 3.2.0. |
| 970 | */ |
| 971 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32BE(SDL_IOStream *src, Uint32 *value); |
| 972 | |
| 973 | /** |
| 974 | * Use this function to read 32 bits of big-endian data from an SDL_IOStream |
| 975 | * and return in native format. |
| 976 | * |
| 977 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 978 | * the native byte order. |
| 979 | * |
| 980 | * This function will return false when the data stream is completely read, |
| 981 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 982 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 983 | * error value and SDL_GetError() will offer a human-readable message. |
| 984 | * |
| 985 | * \param src the stream from which to read data. |
| 986 | * \param value a pointer filled in with the data read. |
| 987 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 988 | * for more information. |
| 989 | * |
| 990 | * \threadsafety This function is not thread safe. |
| 991 | * |
| 992 | * \since This function is available since SDL 3.2.0. |
| 993 | */ |
| 994 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32BE(SDL_IOStream *src, Sint32 *value); |
| 995 | |
| 996 | /** |
| 997 | * Use this function to read 64 bits of little-endian data from an |
| 998 | * SDL_IOStream and return in native format. |
| 999 | * |
| 1000 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 1001 | * the native byte order. |
| 1002 | * |
| 1003 | * This function will return false when the data stream is completely read, |
| 1004 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 1005 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 1006 | * error value and SDL_GetError() will offer a human-readable message. |
| 1007 | * |
| 1008 | * \param src the stream from which to read data. |
| 1009 | * \param value a pointer filled in with the data read. |
| 1010 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1011 | * for more information. |
| 1012 | * |
| 1013 | * \threadsafety This function is not thread safe. |
| 1014 | * |
| 1015 | * \since This function is available since SDL 3.2.0. |
| 1016 | */ |
| 1017 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64LE(SDL_IOStream *src, Uint64 *value); |
| 1018 | |
| 1019 | /** |
| 1020 | * Use this function to read 64 bits of little-endian data from an |
| 1021 | * SDL_IOStream and return in native format. |
| 1022 | * |
| 1023 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 1024 | * the native byte order. |
| 1025 | * |
| 1026 | * This function will return false when the data stream is completely read, |
| 1027 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 1028 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 1029 | * error value and SDL_GetError() will offer a human-readable message. |
| 1030 | * |
| 1031 | * \param src the stream from which to read data. |
| 1032 | * \param value a pointer filled in with the data read. |
| 1033 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1034 | * for more information. |
| 1035 | * |
| 1036 | * \threadsafety This function is not thread safe. |
| 1037 | * |
| 1038 | * \since This function is available since SDL 3.2.0. |
| 1039 | */ |
| 1040 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64LE(SDL_IOStream *src, Sint64 *value); |
| 1041 | |
| 1042 | /** |
| 1043 | * Use this function to read 64 bits of big-endian data from an SDL_IOStream |
| 1044 | * and return in native format. |
| 1045 | * |
| 1046 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 1047 | * the native byte order. |
| 1048 | * |
| 1049 | * This function will return false when the data stream is completely read, |
| 1050 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 1051 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 1052 | * error value and SDL_GetError() will offer a human-readable message. |
| 1053 | * |
| 1054 | * \param src the stream from which to read data. |
| 1055 | * \param value a pointer filled in with the data read. |
| 1056 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1057 | * for more information. |
| 1058 | * |
| 1059 | * \threadsafety This function is not thread safe. |
| 1060 | * |
| 1061 | * \since This function is available since SDL 3.2.0. |
| 1062 | */ |
| 1063 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64BE(SDL_IOStream *src, Uint64 *value); |
| 1064 | |
| 1065 | /** |
| 1066 | * Use this function to read 64 bits of big-endian data from an SDL_IOStream |
| 1067 | * and return in native format. |
| 1068 | * |
| 1069 | * SDL byteswaps the data only if necessary, so the data returned will be in |
| 1070 | * the native byte order. |
| 1071 | * |
| 1072 | * This function will return false when the data stream is completely read, |
| 1073 | * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned |
| 1074 | * and the stream is not at EOF, SDL_GetIOStatus() will return a different |
| 1075 | * error value and SDL_GetError() will offer a human-readable message. |
| 1076 | * |
| 1077 | * \param src the stream from which to read data. |
| 1078 | * \param value a pointer filled in with the data read. |
| 1079 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1080 | * for more information. |
| 1081 | * |
| 1082 | * \threadsafety This function is not thread safe. |
| 1083 | * |
| 1084 | * \since This function is available since SDL 3.2.0. |
| 1085 | */ |
| 1086 | extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64BE(SDL_IOStream *src, Sint64 *value); |
| 1087 | /* @} *//* Read endian functions */ |
| 1088 | |
| 1089 | /** |
| 1090 | * \name Write endian functions |
| 1091 | * |
| 1092 | * Write an item of native format to the specified endianness. |
| 1093 | */ |
| 1094 | /* @{ */ |
| 1095 | |
| 1096 | /** |
| 1097 | * Use this function to write a byte to an SDL_IOStream. |
| 1098 | * |
| 1099 | * \param dst the SDL_IOStream to write to. |
| 1100 | * \param value the byte value to write. |
| 1101 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1102 | * for more information. |
| 1103 | * |
| 1104 | * \threadsafety This function is not thread safe. |
| 1105 | * |
| 1106 | * \since This function is available since SDL 3.2.0. |
| 1107 | */ |
| 1108 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU8(SDL_IOStream *dst, Uint8 value); |
| 1109 | |
| 1110 | /** |
| 1111 | * Use this function to write a signed byte to an SDL_IOStream. |
| 1112 | * |
| 1113 | * \param dst the SDL_IOStream to write to. |
| 1114 | * \param value the byte value to write. |
| 1115 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1116 | * for more information. |
| 1117 | * |
| 1118 | * \threadsafety This function is not thread safe. |
| 1119 | * |
| 1120 | * \since This function is available since SDL 3.2.0. |
| 1121 | */ |
| 1122 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS8(SDL_IOStream *dst, Sint8 value); |
| 1123 | |
| 1124 | /** |
| 1125 | * Use this function to write 16 bits in native format to an SDL_IOStream as |
| 1126 | * little-endian data. |
| 1127 | * |
| 1128 | * SDL byteswaps the data only if necessary, so the application always |
| 1129 | * specifies native format, and the data written will be in little-endian |
| 1130 | * format. |
| 1131 | * |
| 1132 | * \param dst the stream to which data will be written. |
| 1133 | * \param value the data to be written, in native format. |
| 1134 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1135 | * for more information. |
| 1136 | * |
| 1137 | * \threadsafety This function is not thread safe. |
| 1138 | * |
| 1139 | * \since This function is available since SDL 3.2.0. |
| 1140 | */ |
| 1141 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16LE(SDL_IOStream *dst, Uint16 value); |
| 1142 | |
| 1143 | /** |
| 1144 | * Use this function to write 16 bits in native format to an SDL_IOStream as |
| 1145 | * little-endian data. |
| 1146 | * |
| 1147 | * SDL byteswaps the data only if necessary, so the application always |
| 1148 | * specifies native format, and the data written will be in little-endian |
| 1149 | * format. |
| 1150 | * |
| 1151 | * \param dst the stream to which data will be written. |
| 1152 | * \param value the data to be written, in native format. |
| 1153 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1154 | * for more information. |
| 1155 | * |
| 1156 | * \threadsafety This function is not thread safe. |
| 1157 | * |
| 1158 | * \since This function is available since SDL 3.2.0. |
| 1159 | */ |
| 1160 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16LE(SDL_IOStream *dst, Sint16 value); |
| 1161 | |
| 1162 | /** |
| 1163 | * Use this function to write 16 bits in native format to an SDL_IOStream as |
| 1164 | * big-endian data. |
| 1165 | * |
| 1166 | * SDL byteswaps the data only if necessary, so the application always |
| 1167 | * specifies native format, and the data written will be in big-endian format. |
| 1168 | * |
| 1169 | * \param dst the stream to which data will be written. |
| 1170 | * \param value the data to be written, in native format. |
| 1171 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1172 | * for more information. |
| 1173 | * |
| 1174 | * \threadsafety This function is not thread safe. |
| 1175 | * |
| 1176 | * \since This function is available since SDL 3.2.0. |
| 1177 | */ |
| 1178 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16BE(SDL_IOStream *dst, Uint16 value); |
| 1179 | |
| 1180 | /** |
| 1181 | * Use this function to write 16 bits in native format to an SDL_IOStream as |
| 1182 | * big-endian data. |
| 1183 | * |
| 1184 | * SDL byteswaps the data only if necessary, so the application always |
| 1185 | * specifies native format, and the data written will be in big-endian format. |
| 1186 | * |
| 1187 | * \param dst the stream to which data will be written. |
| 1188 | * \param value the data to be written, in native format. |
| 1189 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1190 | * for more information. |
| 1191 | * |
| 1192 | * \threadsafety This function is not thread safe. |
| 1193 | * |
| 1194 | * \since This function is available since SDL 3.2.0. |
| 1195 | */ |
| 1196 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16BE(SDL_IOStream *dst, Sint16 value); |
| 1197 | |
| 1198 | /** |
| 1199 | * Use this function to write 32 bits in native format to an SDL_IOStream as |
| 1200 | * little-endian data. |
| 1201 | * |
| 1202 | * SDL byteswaps the data only if necessary, so the application always |
| 1203 | * specifies native format, and the data written will be in little-endian |
| 1204 | * format. |
| 1205 | * |
| 1206 | * \param dst the stream to which data will be written. |
| 1207 | * \param value the data to be written, in native format. |
| 1208 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1209 | * for more information. |
| 1210 | * |
| 1211 | * \threadsafety This function is not thread safe. |
| 1212 | * |
| 1213 | * \since This function is available since SDL 3.2.0. |
| 1214 | */ |
| 1215 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32LE(SDL_IOStream *dst, Uint32 value); |
| 1216 | |
| 1217 | /** |
| 1218 | * Use this function to write 32 bits in native format to an SDL_IOStream as |
| 1219 | * little-endian data. |
| 1220 | * |
| 1221 | * SDL byteswaps the data only if necessary, so the application always |
| 1222 | * specifies native format, and the data written will be in little-endian |
| 1223 | * format. |
| 1224 | * |
| 1225 | * \param dst the stream to which data will be written. |
| 1226 | * \param value the data to be written, in native format. |
| 1227 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1228 | * for more information. |
| 1229 | * |
| 1230 | * \threadsafety This function is not thread safe. |
| 1231 | * |
| 1232 | * \since This function is available since SDL 3.2.0. |
| 1233 | */ |
| 1234 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32LE(SDL_IOStream *dst, Sint32 value); |
| 1235 | |
| 1236 | /** |
| 1237 | * Use this function to write 32 bits in native format to an SDL_IOStream as |
| 1238 | * big-endian data. |
| 1239 | * |
| 1240 | * SDL byteswaps the data only if necessary, so the application always |
| 1241 | * specifies native format, and the data written will be in big-endian format. |
| 1242 | * |
| 1243 | * \param dst the stream to which data will be written. |
| 1244 | * \param value the data to be written, in native format. |
| 1245 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1246 | * for more information. |
| 1247 | * |
| 1248 | * \threadsafety This function is not thread safe. |
| 1249 | * |
| 1250 | * \since This function is available since SDL 3.2.0. |
| 1251 | */ |
| 1252 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32BE(SDL_IOStream *dst, Uint32 value); |
| 1253 | |
| 1254 | /** |
| 1255 | * Use this function to write 32 bits in native format to an SDL_IOStream as |
| 1256 | * big-endian data. |
| 1257 | * |
| 1258 | * SDL byteswaps the data only if necessary, so the application always |
| 1259 | * specifies native format, and the data written will be in big-endian format. |
| 1260 | * |
| 1261 | * \param dst the stream to which data will be written. |
| 1262 | * \param value the data to be written, in native format. |
| 1263 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1264 | * for more information. |
| 1265 | * |
| 1266 | * \threadsafety This function is not thread safe. |
| 1267 | * |
| 1268 | * \since This function is available since SDL 3.2.0. |
| 1269 | */ |
| 1270 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32BE(SDL_IOStream *dst, Sint32 value); |
| 1271 | |
| 1272 | /** |
| 1273 | * Use this function to write 64 bits in native format to an SDL_IOStream as |
| 1274 | * little-endian data. |
| 1275 | * |
| 1276 | * SDL byteswaps the data only if necessary, so the application always |
| 1277 | * specifies native format, and the data written will be in little-endian |
| 1278 | * format. |
| 1279 | * |
| 1280 | * \param dst the stream to which data will be written. |
| 1281 | * \param value the data to be written, in native format. |
| 1282 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1283 | * for more information. |
| 1284 | * |
| 1285 | * \threadsafety This function is not thread safe. |
| 1286 | * |
| 1287 | * \since This function is available since SDL 3.2.0. |
| 1288 | */ |
| 1289 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64LE(SDL_IOStream *dst, Uint64 value); |
| 1290 | |
| 1291 | /** |
| 1292 | * Use this function to write 64 bits in native format to an SDL_IOStream as |
| 1293 | * little-endian data. |
| 1294 | * |
| 1295 | * SDL byteswaps the data only if necessary, so the application always |
| 1296 | * specifies native format, and the data written will be in little-endian |
| 1297 | * format. |
| 1298 | * |
| 1299 | * \param dst the stream to which data will be written. |
| 1300 | * \param value the data to be written, in native format. |
| 1301 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1302 | * for more information. |
| 1303 | * |
| 1304 | * \threadsafety This function is not thread safe. |
| 1305 | * |
| 1306 | * \since This function is available since SDL 3.2.0. |
| 1307 | */ |
| 1308 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64LE(SDL_IOStream *dst, Sint64 value); |
| 1309 | |
| 1310 | /** |
| 1311 | * Use this function to write 64 bits in native format to an SDL_IOStream as |
| 1312 | * big-endian data. |
| 1313 | * |
| 1314 | * SDL byteswaps the data only if necessary, so the application always |
| 1315 | * specifies native format, and the data written will be in big-endian format. |
| 1316 | * |
| 1317 | * \param dst the stream to which data will be written. |
| 1318 | * \param value the data to be written, in native format. |
| 1319 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1320 | * for more information. |
| 1321 | * |
| 1322 | * \threadsafety This function is not thread safe. |
| 1323 | * |
| 1324 | * \since This function is available since SDL 3.2.0. |
| 1325 | */ |
| 1326 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64BE(SDL_IOStream *dst, Uint64 value); |
| 1327 | |
| 1328 | /** |
| 1329 | * Use this function to write 64 bits in native format to an SDL_IOStream as |
| 1330 | * big-endian data. |
| 1331 | * |
| 1332 | * SDL byteswaps the data only if necessary, so the application always |
| 1333 | * specifies native format, and the data written will be in big-endian format. |
| 1334 | * |
| 1335 | * \param dst the stream to which data will be written. |
| 1336 | * \param value the data to be written, in native format. |
| 1337 | * \returns true on successful write or false on failure; call SDL_GetError() |
| 1338 | * for more information. |
| 1339 | * |
| 1340 | * \threadsafety This function is not thread safe. |
| 1341 | * |
| 1342 | * \since This function is available since SDL 3.2.0. |
| 1343 | */ |
| 1344 | extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64BE(SDL_IOStream *dst, Sint64 value); |
| 1345 | |
| 1346 | /* @} *//* Write endian functions */ |
| 1347 | |
| 1348 | /* Ends C function definitions when using C++ */ |
| 1349 | #ifdef __cplusplus |
| 1350 | } |
| 1351 | #endif |
| 1352 | #include <SDL3/SDL_close_code.h> |
| 1353 | |
| 1354 | #endif /* SDL_iostream_h_ */ |
| 1355 | |