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`.
115 *
116 * On an incomplete read, you should set `*status` to a value from the
117 * SDL_IOStatus enum. You do not have to explicitly set this on
118 * a complete, successful read.
119 *
120 * \return the number of bytes read
121 */
122 size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_IOStatus *status);
123
124 /**
125 * Write exactly `size` bytes from the area pointed at by `ptr`
126 * to data stream.
127 *
128 * On an incomplete write, you should set `*status` to a value from the
129 * SDL_IOStatus enum. You do not have to explicitly set this on
130 * a complete, successful write.
131 *
132 * \return the number of bytes written
133 */
134 size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_IOStatus *status);
135
136 /**
137 * If the stream is buffering, make sure the data is written out.
138 *
139 * On failure, you should set `*status` to a value from the
140 * SDL_IOStatus enum. You do not have to explicitly set this on
141 * a successful flush.
142 *
143 * \return true if successful or false on write error when flushing data.
144 */
145 bool (SDLCALL *flush)(void *userdata, SDL_IOStatus *status);
146
147 /**
148 * Close and free any allocated resources.
149 *
150 * This does not guarantee file writes will sync to physical media; they
151 * can be in the system's file cache, waiting to go to disk.
152 *
153 * The SDL_IOStream is still destroyed even if this fails, so clean up anything
154 * even if flushing buffers, etc, returns an error.
155 *
156 * \return true if successful or false on write error when flushing data.
157 */
158 bool (SDLCALL *close)(void *userdata);
159
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 This function is not thread safe.
264 *
265 * \since This function is available since SDL 3.2.0.
266 *
267 * \sa SDL_CloseIO
268 * \sa SDL_FlushIO
269 * \sa SDL_ReadIO
270 * \sa SDL_SeekIO
271 * \sa SDL_TellIO
272 * \sa SDL_WriteIO
273 */
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 This function is not thread safe.
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 This function is not thread safe.
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 This function is not thread safe.
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 This function is not thread safe.
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 This function is not thread safe.
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 This function is not thread safe.
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 * \param context a pointer to an SDL_IOStream structure.
584 * \param ptr a pointer to a buffer to read data into.
585 * \param size the number of bytes to read from the data source.
586 * \returns the number of bytes read, or 0 on end of file or other failure;
587 * call SDL_GetError() for more information.
588 *
589 * \threadsafety This function is not thread safe.
590 *
591 * \since This function is available since SDL 3.2.0.
592 *
593 * \sa SDL_WriteIO
594 * \sa SDL_GetIOStatus
595 */
596extern SDL_DECLSPEC size_t SDLCALL SDL_ReadIO(SDL_IOStream *context, void *ptr, size_t size);
597
598/**
599 * Write to an SDL_IOStream data stream.
600 *
601 * This function writes exactly `size` bytes from the area pointed at by `ptr`
602 * to the stream. If this fails for any reason, it'll return less than `size`
603 * to demonstrate how far the write progressed. On success, it returns `size`.
604 *
605 * On error, this function still attempts to write as much as possible, so it
606 * might return a positive value less than the requested write size.
607 *
608 * The caller can use SDL_GetIOStatus() to determine if the problem is
609 * recoverable, such as a non-blocking write that can simply be retried later,
610 * or a fatal error.
611 *
612 * \param context a pointer to an SDL_IOStream structure.
613 * \param ptr a pointer to a buffer containing data to write.
614 * \param size the number of bytes to write.
615 * \returns the number of bytes written, which will be less than `size` on
616 * failure; call SDL_GetError() for more information.
617 *
618 * \threadsafety This function is not thread safe.
619 *
620 * \since This function is available since SDL 3.2.0.
621 *
622 * \sa SDL_IOprintf
623 * \sa SDL_ReadIO
624 * \sa SDL_SeekIO
625 * \sa SDL_FlushIO
626 * \sa SDL_GetIOStatus
627 */
628extern SDL_DECLSPEC size_t SDLCALL SDL_WriteIO(SDL_IOStream *context, const void *ptr, size_t size);
629
630/**
631 * Print to an SDL_IOStream data stream.
632 *
633 * This function does formatted printing to the stream.
634 *
635 * \param context a pointer to an SDL_IOStream structure.
636 * \param fmt a printf() style format string.
637 * \param ... additional parameters matching % tokens in the `fmt` string, if
638 * any.
639 * \returns the number of bytes written or 0 on failure; call SDL_GetError()
640 * for more information.
641 *
642 * \threadsafety This function is not thread safe.
643 *
644 * \since This function is available since SDL 3.2.0.
645 *
646 * \sa SDL_IOvprintf
647 * \sa SDL_WriteIO
648 */
649extern SDL_DECLSPEC size_t SDLCALL SDL_IOprintf(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
650
651/**
652 * Print to an SDL_IOStream data stream.
653 *
654 * This function does formatted printing to the stream.
655 *
656 * \param context a pointer to an SDL_IOStream structure.
657 * \param fmt a printf() style format string.
658 * \param ap a variable argument list.
659 * \returns the number of bytes written or 0 on failure; call SDL_GetError()
660 * for more information.
661 *
662 * \threadsafety This function is not thread safe.
663 *
664 * \since This function is available since SDL 3.2.0.
665 *
666 * \sa SDL_IOprintf
667 * \sa SDL_WriteIO
668 */
669extern 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);
670
671/**
672 * Flush any buffered data in the stream.
673 *
674 * This function makes sure that any buffered data is written to the stream.
675 * Normally this isn't necessary but if the stream is a pipe or socket it
676 * guarantees that any pending data is sent.
677 *
678 * \param context SDL_IOStream structure to flush.
679 * \returns true on success or false on failure; call SDL_GetError() for more
680 * information.
681 *
682 * \threadsafety This function is not thread safe.
683 *
684 * \since This function is available since SDL 3.2.0.
685 *
686 * \sa SDL_OpenIO
687 * \sa SDL_WriteIO
688 */
689extern SDL_DECLSPEC bool SDLCALL SDL_FlushIO(SDL_IOStream *context);
690
691/**
692 * Load all the data from an SDL data stream.
693 *
694 * The data is allocated with a zero byte at the end (null terminated) for
695 * convenience. This extra byte is not included in the value reported via
696 * `datasize`.
697 *
698 * The data should be freed with SDL_free().
699 *
700 * \param src the SDL_IOStream to read all available data from.
701 * \param datasize a pointer filled in with the number of bytes read, may be
702 * NULL.
703 * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
704 * in the case of an error.
705 * \returns the data or NULL on failure; call SDL_GetError() for more
706 * information.
707 *
708 * \threadsafety This function is not thread safe.
709 *
710 * \since This function is available since SDL 3.2.0.
711 *
712 * \sa SDL_LoadFile
713 * \sa SDL_SaveFile_IO
714 */
715extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile_IO(SDL_IOStream *src, size_t *datasize, bool closeio);
716
717/**
718 * Load all the data from a file path.
719 *
720 * The data is allocated with a zero byte at the end (null terminated) for
721 * convenience. This extra byte is not included in the value reported via
722 * `datasize`.
723 *
724 * The data should be freed with SDL_free().
725 *
726 * \param file the path to read all available data from.
727 * \param datasize if not NULL, will store the number of bytes read.
728 * \returns the data or NULL on failure; call SDL_GetError() for more
729 * information.
730 *
731 * \threadsafety This function is not thread safe.
732 *
733 * \since This function is available since SDL 3.2.0.
734 *
735 * \sa SDL_LoadFile_IO
736 * \sa SDL_SaveFile
737 */
738extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
739
740/**
741 * Save all the data into an SDL data stream.
742 *
743 * \param src the SDL_IOStream to write all data to.
744 * \param data the data to be written. If datasize is 0, may be NULL or a
745 * invalid pointer.
746 * \param datasize the number of bytes to be written.
747 * \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
748 * in the case of an error.
749 * \returns true on success or false on failure; call SDL_GetError() for more
750 * information.
751 *
752 * \threadsafety This function is not thread safe.
753 *
754 * \since This function is available since SDL 3.2.0.
755 *
756 * \sa SDL_SaveFile
757 * \sa SDL_LoadFile_IO
758 */
759extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile_IO(SDL_IOStream *src, const void *data, size_t datasize, bool closeio);
760
761/**
762 * Save all the data into a file path.
763 *
764 * \param file the path to write all available data into.
765 * \param data the data to be written. If datasize is 0, may be NULL or a
766 * invalid pointer.
767 * \param datasize the number of bytes to be written.
768 * \returns true on success or false on failure; call SDL_GetError() for more
769 * information.
770 *
771 * \threadsafety This function is not thread safe.
772 *
773 * \since This function is available since SDL 3.2.0.
774 *
775 * \sa SDL_SaveFile_IO
776 * \sa SDL_LoadFile
777 */
778extern SDL_DECLSPEC bool SDLCALL SDL_SaveFile(const char *file, const void *data, size_t datasize);
779
780/**
781 * \name Read endian functions
782 *
783 * Read an item of the specified endianness and return in native format.
784 */
785/* @{ */
786
787/**
788 * Use this function to read a byte from an SDL_IOStream.
789 *
790 * This function will return false when the data stream is completely read,
791 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
792 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
793 * error value and SDL_GetError() will offer a human-readable message.
794 *
795 * \param src the SDL_IOStream to read from.
796 * \param value a pointer filled in with the data read.
797 * \returns true on success or false on failure or EOF; call SDL_GetError()
798 * for more information.
799 *
800 * \threadsafety This function is not thread safe.
801 *
802 * \since This function is available since SDL 3.2.0.
803 */
804extern SDL_DECLSPEC bool SDLCALL SDL_ReadU8(SDL_IOStream *src, Uint8 *value);
805
806/**
807 * Use this function to read a signed byte from an SDL_IOStream.
808 *
809 * This function will return false when the data stream is completely read,
810 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
811 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
812 * error value and SDL_GetError() will offer a human-readable message.
813 *
814 * \param src the SDL_IOStream to read from.
815 * \param value a pointer filled in with the data read.
816 * \returns true on success or false on failure; call SDL_GetError() for more
817 * information.
818 *
819 * \threadsafety This function is not thread safe.
820 *
821 * \since This function is available since SDL 3.2.0.
822 */
823extern SDL_DECLSPEC bool SDLCALL SDL_ReadS8(SDL_IOStream *src, Sint8 *value);
824
825/**
826 * Use this function to read 16 bits of little-endian data from an
827 * SDL_IOStream and return in native format.
828 *
829 * SDL byteswaps the data only if necessary, so the data returned will be in
830 * the native byte order.
831 *
832 * This function will return false when the data stream is completely read,
833 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
834 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
835 * error value and SDL_GetError() will offer a human-readable message.
836 *
837 * \param src the stream from which to read data.
838 * \param value a pointer filled in with the data read.
839 * \returns true on successful read or false on failure; call SDL_GetError()
840 * for more information.
841 *
842 * \threadsafety This function is not thread safe.
843 *
844 * \since This function is available since SDL 3.2.0.
845 */
846extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16LE(SDL_IOStream *src, Uint16 *value);
847
848/**
849 * Use this function to read 16 bits of little-endian data from an
850 * SDL_IOStream and return in native format.
851 *
852 * SDL byteswaps the data only if necessary, so the data returned will be in
853 * the native byte order.
854 *
855 * This function will return false when the data stream is completely read,
856 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
857 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
858 * error value and SDL_GetError() will offer a human-readable message.
859 *
860 * \param src the stream from which to read data.
861 * \param value a pointer filled in with the data read.
862 * \returns true on successful read or false on failure; call SDL_GetError()
863 * for more information.
864 *
865 * \threadsafety This function is not thread safe.
866 *
867 * \since This function is available since SDL 3.2.0.
868 */
869extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16LE(SDL_IOStream *src, Sint16 *value);
870
871/**
872 * Use this function to read 16 bits of big-endian data from an SDL_IOStream
873 * and return in native format.
874 *
875 * SDL byteswaps the data only if necessary, so the data returned will be in
876 * the native byte order.
877 *
878 * This function will return false when the data stream is completely read,
879 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
880 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
881 * error value and SDL_GetError() will offer a human-readable message.
882 *
883 * \param src the stream from which to read data.
884 * \param value a pointer filled in with the data read.
885 * \returns true on successful read or false on failure; call SDL_GetError()
886 * for more information.
887 *
888 * \threadsafety This function is not thread safe.
889 *
890 * \since This function is available since SDL 3.2.0.
891 */
892extern SDL_DECLSPEC bool SDLCALL SDL_ReadU16BE(SDL_IOStream *src, Uint16 *value);
893
894/**
895 * Use this function to read 16 bits of big-endian data from an SDL_IOStream
896 * and return in native format.
897 *
898 * SDL byteswaps the data only if necessary, so the data returned will be in
899 * the native byte order.
900 *
901 * This function will return false when the data stream is completely read,
902 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
903 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
904 * error value and SDL_GetError() will offer a human-readable message.
905 *
906 * \param src the stream from which to read data.
907 * \param value a pointer filled in with the data read.
908 * \returns true on successful read or false on failure; call SDL_GetError()
909 * for more information.
910 *
911 * \threadsafety This function is not thread safe.
912 *
913 * \since This function is available since SDL 3.2.0.
914 */
915extern SDL_DECLSPEC bool SDLCALL SDL_ReadS16BE(SDL_IOStream *src, Sint16 *value);
916
917/**
918 * Use this function to read 32 bits of little-endian data from an
919 * SDL_IOStream and return in native format.
920 *
921 * SDL byteswaps the data only if necessary, so the data returned will be in
922 * the native byte order.
923 *
924 * This function will return false when the data stream is completely read,
925 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
926 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
927 * error value and SDL_GetError() will offer a human-readable message.
928 *
929 * \param src the stream from which to read data.
930 * \param value a pointer filled in with the data read.
931 * \returns true on successful read or false on failure; call SDL_GetError()
932 * for more information.
933 *
934 * \threadsafety This function is not thread safe.
935 *
936 * \since This function is available since SDL 3.2.0.
937 */
938extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32LE(SDL_IOStream *src, Uint32 *value);
939
940/**
941 * Use this function to read 32 bits of little-endian data from an
942 * SDL_IOStream and return in native format.
943 *
944 * SDL byteswaps the data only if necessary, so the data returned will be in
945 * the native byte order.
946 *
947 * This function will return false when the data stream is completely read,
948 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
949 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
950 * error value and SDL_GetError() will offer a human-readable message.
951 *
952 * \param src the stream from which to read data.
953 * \param value a pointer filled in with the data read.
954 * \returns true on successful read or false on failure; call SDL_GetError()
955 * for more information.
956 *
957 * \threadsafety This function is not thread safe.
958 *
959 * \since This function is available since SDL 3.2.0.
960 */
961extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32LE(SDL_IOStream *src, Sint32 *value);
962
963/**
964 * Use this function to read 32 bits of big-endian data from an SDL_IOStream
965 * and return in native format.
966 *
967 * SDL byteswaps the data only if necessary, so the data returned will be in
968 * the native byte order.
969 *
970 * This function will return false when the data stream is completely read,
971 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
972 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
973 * error value and SDL_GetError() will offer a human-readable message.
974 *
975 * \param src the stream from which to read data.
976 * \param value a pointer filled in with the data read.
977 * \returns true on successful read or false on failure; call SDL_GetError()
978 * for more information.
979 *
980 * \threadsafety This function is not thread safe.
981 *
982 * \since This function is available since SDL 3.2.0.
983 */
984extern SDL_DECLSPEC bool SDLCALL SDL_ReadU32BE(SDL_IOStream *src, Uint32 *value);
985
986/**
987 * Use this function to read 32 bits of big-endian data from an SDL_IOStream
988 * and return in native format.
989 *
990 * SDL byteswaps the data only if necessary, so the data returned will be in
991 * the native byte order.
992 *
993 * This function will return false when the data stream is completely read,
994 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
995 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
996 * error value and SDL_GetError() will offer a human-readable message.
997 *
998 * \param src the stream from which to read data.
999 * \param value a pointer filled in with the data read.
1000 * \returns true on successful read or false on failure; call SDL_GetError()
1001 * for more information.
1002 *
1003 * \threadsafety This function is not thread safe.
1004 *
1005 * \since This function is available since SDL 3.2.0.
1006 */
1007extern SDL_DECLSPEC bool SDLCALL SDL_ReadS32BE(SDL_IOStream *src, Sint32 *value);
1008
1009/**
1010 * Use this function to read 64 bits of little-endian data from an
1011 * SDL_IOStream and return in native format.
1012 *
1013 * SDL byteswaps the data only if necessary, so the data returned will be in
1014 * the native byte order.
1015 *
1016 * This function will return false when the data stream is completely read,
1017 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
1018 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
1019 * error value and SDL_GetError() will offer a human-readable message.
1020 *
1021 * \param src the stream from which to read data.
1022 * \param value a pointer filled in with the data read.
1023 * \returns true on successful read or false on failure; call SDL_GetError()
1024 * for more information.
1025 *
1026 * \threadsafety This function is not thread safe.
1027 *
1028 * \since This function is available since SDL 3.2.0.
1029 */
1030extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64LE(SDL_IOStream *src, Uint64 *value);
1031
1032/**
1033 * Use this function to read 64 bits of little-endian data from an
1034 * SDL_IOStream and return in native format.
1035 *
1036 * SDL byteswaps the data only if necessary, so the data returned will be in
1037 * the native byte order.
1038 *
1039 * This function will return false when the data stream is completely read,
1040 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
1041 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
1042 * error value and SDL_GetError() will offer a human-readable message.
1043 *
1044 * \param src the stream from which to read data.
1045 * \param value a pointer filled in with the data read.
1046 * \returns true on successful read or false on failure; call SDL_GetError()
1047 * for more information.
1048 *
1049 * \threadsafety This function is not thread safe.
1050 *
1051 * \since This function is available since SDL 3.2.0.
1052 */
1053extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64LE(SDL_IOStream *src, Sint64 *value);
1054
1055/**
1056 * Use this function to read 64 bits of big-endian data from an SDL_IOStream
1057 * and return in native format.
1058 *
1059 * SDL byteswaps the data only if necessary, so the data returned will be in
1060 * the native byte order.
1061 *
1062 * This function will return false when the data stream is completely read,
1063 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
1064 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
1065 * error value and SDL_GetError() will offer a human-readable message.
1066 *
1067 * \param src the stream from which to read data.
1068 * \param value a pointer filled in with the data read.
1069 * \returns true on successful read or false on failure; call SDL_GetError()
1070 * for more information.
1071 *
1072 * \threadsafety This function is not thread safe.
1073 *
1074 * \since This function is available since SDL 3.2.0.
1075 */
1076extern SDL_DECLSPEC bool SDLCALL SDL_ReadU64BE(SDL_IOStream *src, Uint64 *value);
1077
1078/**
1079 * Use this function to read 64 bits of big-endian data from an SDL_IOStream
1080 * and return in native format.
1081 *
1082 * SDL byteswaps the data only if necessary, so the data returned will be in
1083 * the native byte order.
1084 *
1085 * This function will return false when the data stream is completely read,
1086 * and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. If false is returned
1087 * and the stream is not at EOF, SDL_GetIOStatus() will return a different
1088 * error value and SDL_GetError() will offer a human-readable message.
1089 *
1090 * \param src the stream from which to read data.
1091 * \param value a pointer filled in with the data read.
1092 * \returns true on successful read or false on failure; call SDL_GetError()
1093 * for more information.
1094 *
1095 * \threadsafety This function is not thread safe.
1096 *
1097 * \since This function is available since SDL 3.2.0.
1098 */
1099extern SDL_DECLSPEC bool SDLCALL SDL_ReadS64BE(SDL_IOStream *src, Sint64 *value);
1100/* @} *//* Read endian functions */
1101
1102/**
1103 * \name Write endian functions
1104 *
1105 * Write an item of native format to the specified endianness.
1106 */
1107/* @{ */
1108
1109/**
1110 * Use this function to write a byte to an SDL_IOStream.
1111 *
1112 * \param dst the SDL_IOStream to write to.
1113 * \param value the byte value to write.
1114 * \returns true on successful write or false on failure; call SDL_GetError()
1115 * for more information.
1116 *
1117 * \threadsafety This function is not thread safe.
1118 *
1119 * \since This function is available since SDL 3.2.0.
1120 */
1121extern SDL_DECLSPEC bool SDLCALL SDL_WriteU8(SDL_IOStream *dst, Uint8 value);
1122
1123/**
1124 * Use this function to write a signed byte to an SDL_IOStream.
1125 *
1126 * \param dst the SDL_IOStream to write to.
1127 * \param value the byte value to write.
1128 * \returns true on successful write or false on failure; call SDL_GetError()
1129 * for more information.
1130 *
1131 * \threadsafety This function is not thread safe.
1132 *
1133 * \since This function is available since SDL 3.2.0.
1134 */
1135extern SDL_DECLSPEC bool SDLCALL SDL_WriteS8(SDL_IOStream *dst, Sint8 value);
1136
1137/**
1138 * Use this function to write 16 bits in native format to an SDL_IOStream as
1139 * little-endian data.
1140 *
1141 * SDL byteswaps the data only if necessary, so the application always
1142 * specifies native format, and the data written will be in little-endian
1143 * format.
1144 *
1145 * \param dst the stream to which data will be written.
1146 * \param value the data to be written, in native format.
1147 * \returns true on successful write or false on failure; call SDL_GetError()
1148 * for more information.
1149 *
1150 * \threadsafety This function is not thread safe.
1151 *
1152 * \since This function is available since SDL 3.2.0.
1153 */
1154extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16LE(SDL_IOStream *dst, Uint16 value);
1155
1156/**
1157 * Use this function to write 16 bits in native format to an SDL_IOStream as
1158 * little-endian data.
1159 *
1160 * SDL byteswaps the data only if necessary, so the application always
1161 * specifies native format, and the data written will be in little-endian
1162 * format.
1163 *
1164 * \param dst the stream to which data will be written.
1165 * \param value the data to be written, in native format.
1166 * \returns true on successful write or false on failure; call SDL_GetError()
1167 * for more information.
1168 *
1169 * \threadsafety This function is not thread safe.
1170 *
1171 * \since This function is available since SDL 3.2.0.
1172 */
1173extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16LE(SDL_IOStream *dst, Sint16 value);
1174
1175/**
1176 * Use this function to write 16 bits in native format to an SDL_IOStream as
1177 * big-endian data.
1178 *
1179 * SDL byteswaps the data only if necessary, so the application always
1180 * specifies native format, and the data written will be in big-endian format.
1181 *
1182 * \param dst the stream to which data will be written.
1183 * \param value the data to be written, in native format.
1184 * \returns true on successful write or false on failure; call SDL_GetError()
1185 * for more information.
1186 *
1187 * \threadsafety This function is not thread safe.
1188 *
1189 * \since This function is available since SDL 3.2.0.
1190 */
1191extern SDL_DECLSPEC bool SDLCALL SDL_WriteU16BE(SDL_IOStream *dst, Uint16 value);
1192
1193/**
1194 * Use this function to write 16 bits in native format to an SDL_IOStream as
1195 * big-endian data.
1196 *
1197 * SDL byteswaps the data only if necessary, so the application always
1198 * specifies native format, and the data written will be in big-endian format.
1199 *
1200 * \param dst the stream to which data will be written.
1201 * \param value the data to be written, in native format.
1202 * \returns true on successful write or false on failure; call SDL_GetError()
1203 * for more information.
1204 *
1205 * \threadsafety This function is not thread safe.
1206 *
1207 * \since This function is available since SDL 3.2.0.
1208 */
1209extern SDL_DECLSPEC bool SDLCALL SDL_WriteS16BE(SDL_IOStream *dst, Sint16 value);
1210
1211/**
1212 * Use this function to write 32 bits in native format to an SDL_IOStream as
1213 * little-endian data.
1214 *
1215 * SDL byteswaps the data only if necessary, so the application always
1216 * specifies native format, and the data written will be in little-endian
1217 * format.
1218 *
1219 * \param dst the stream to which data will be written.
1220 * \param value the data to be written, in native format.
1221 * \returns true on successful write or false on failure; call SDL_GetError()
1222 * for more information.
1223 *
1224 * \threadsafety This function is not thread safe.
1225 *
1226 * \since This function is available since SDL 3.2.0.
1227 */
1228extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32LE(SDL_IOStream *dst, Uint32 value);
1229
1230/**
1231 * Use this function to write 32 bits in native format to an SDL_IOStream as
1232 * little-endian data.
1233 *
1234 * SDL byteswaps the data only if necessary, so the application always
1235 * specifies native format, and the data written will be in little-endian
1236 * format.
1237 *
1238 * \param dst the stream to which data will be written.
1239 * \param value the data to be written, in native format.
1240 * \returns true on successful write or false on failure; call SDL_GetError()
1241 * for more information.
1242 *
1243 * \threadsafety This function is not thread safe.
1244 *
1245 * \since This function is available since SDL 3.2.0.
1246 */
1247extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32LE(SDL_IOStream *dst, Sint32 value);
1248
1249/**
1250 * Use this function to write 32 bits in native format to an SDL_IOStream as
1251 * big-endian data.
1252 *
1253 * SDL byteswaps the data only if necessary, so the application always
1254 * specifies native format, and the data written will be in big-endian format.
1255 *
1256 * \param dst the stream to which data will be written.
1257 * \param value the data to be written, in native format.
1258 * \returns true on successful write or false on failure; call SDL_GetError()
1259 * for more information.
1260 *
1261 * \threadsafety This function is not thread safe.
1262 *
1263 * \since This function is available since SDL 3.2.0.
1264 */
1265extern SDL_DECLSPEC bool SDLCALL SDL_WriteU32BE(SDL_IOStream *dst, Uint32 value);
1266
1267/**
1268 * Use this function to write 32 bits in native format to an SDL_IOStream as
1269 * big-endian data.
1270 *
1271 * SDL byteswaps the data only if necessary, so the application always
1272 * specifies native format, and the data written will be in big-endian format.
1273 *
1274 * \param dst the stream to which data will be written.
1275 * \param value the data to be written, in native format.
1276 * \returns true on successful write or false on failure; call SDL_GetError()
1277 * for more information.
1278 *
1279 * \threadsafety This function is not thread safe.
1280 *
1281 * \since This function is available since SDL 3.2.0.
1282 */
1283extern SDL_DECLSPEC bool SDLCALL SDL_WriteS32BE(SDL_IOStream *dst, Sint32 value);
1284
1285/**
1286 * Use this function to write 64 bits in native format to an SDL_IOStream as
1287 * little-endian data.
1288 *
1289 * SDL byteswaps the data only if necessary, so the application always
1290 * specifies native format, and the data written will be in little-endian
1291 * format.
1292 *
1293 * \param dst the stream to which data will be written.
1294 * \param value the data to be written, in native format.
1295 * \returns true on successful write or false on failure; call SDL_GetError()
1296 * for more information.
1297 *
1298 * \threadsafety This function is not thread safe.
1299 *
1300 * \since This function is available since SDL 3.2.0.
1301 */
1302extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64LE(SDL_IOStream *dst, Uint64 value);
1303
1304/**
1305 * Use this function to write 64 bits in native format to an SDL_IOStream as
1306 * little-endian data.
1307 *
1308 * SDL byteswaps the data only if necessary, so the application always
1309 * specifies native format, and the data written will be in little-endian
1310 * format.
1311 *
1312 * \param dst the stream to which data will be written.
1313 * \param value the data to be written, in native format.
1314 * \returns true on successful write or false on failure; call SDL_GetError()
1315 * for more information.
1316 *
1317 * \threadsafety This function is not thread safe.
1318 *
1319 * \since This function is available since SDL 3.2.0.
1320 */
1321extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64LE(SDL_IOStream *dst, Sint64 value);
1322
1323/**
1324 * Use this function to write 64 bits in native format to an SDL_IOStream as
1325 * big-endian data.
1326 *
1327 * SDL byteswaps the data only if necessary, so the application always
1328 * specifies native format, and the data written will be in big-endian format.
1329 *
1330 * \param dst the stream to which data will be written.
1331 * \param value the data to be written, in native format.
1332 * \returns true on successful write or false on failure; call SDL_GetError()
1333 * for more information.
1334 *
1335 * \threadsafety This function is not thread safe.
1336 *
1337 * \since This function is available since SDL 3.2.0.
1338 */
1339extern SDL_DECLSPEC bool SDLCALL SDL_WriteU64BE(SDL_IOStream *dst, Uint64 value);
1340
1341/**
1342 * Use this function to write 64 bits in native format to an SDL_IOStream as
1343 * big-endian data.
1344 *
1345 * SDL byteswaps the data only if necessary, so the application always
1346 * specifies native format, and the data written will be in big-endian format.
1347 *
1348 * \param dst the stream to which data will be written.
1349 * \param value the data to be written, in native format.
1350 * \returns true on successful write or false on failure; call SDL_GetError()
1351 * for more information.
1352 *
1353 * \threadsafety This function is not thread safe.
1354 *
1355 * \since This function is available since SDL 3.2.0.
1356 */
1357extern SDL_DECLSPEC bool SDLCALL SDL_WriteS64BE(SDL_IOStream *dst, Sint64 value);
1358
1359/* @} *//* Write endian functions */
1360
1361/* Ends C function definitions when using C++ */
1362#ifdef __cplusplus
1363}
1364#endif
1365#include <SDL3/SDL_close_code.h>
1366
1367#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:425
int64_t Sint64
Definition SDL_stdinc.h:472
uint16_t Uint16
Definition SDL_stdinc.h:443
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
int8_t Sint8
Definition SDL_stdinc.h:416
int32_t Sint32
Definition SDL_stdinc.h:452
SDL_MALLOC size_t size
int16_t Sint16
Definition SDL_stdinc.h:434
#define SDL_PRINTF_FORMAT_STRING
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:209
#define bool
Definition SDL_stdinc.h:72
uint64_t Uint64
Definition SDL_stdinc.h:483
uint32_t Uint32
Definition SDL_stdinc.h:461
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)