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