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