SDL 3.0
SDL_rwops.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2023 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/**
23 * \file SDL_rwops.h
24 *
25 * This file provides a general interface for SDL to read and write
26 * data streams. It can easily be extended to files, memory, etc.
27 */
28
29#ifndef SDL_rwops_h_
30#define SDL_rwops_h_
31
32#include <SDL3/SDL_stdinc.h>
33#include <SDL3/SDL_error.h>
34#include <SDL3/SDL_properties.h>
35
36#include <SDL3/SDL_begin_code.h>
37/* Set up for C function definitions, even when using C++ */
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/* RWops types */
43#define SDL_RWOPS_UNKNOWN 0 /**< Unknown stream type */
44#define SDL_RWOPS_WINFILE 1 /**< Win32 file */
45#define SDL_RWOPS_STDFILE 2 /**< Stdio file */
46#define SDL_RWOPS_JNIFILE 3 /**< Android asset */
47#define SDL_RWOPS_MEMORY 4 /**< Memory stream */
48#define SDL_RWOPS_MEMORY_RO 5 /**< Read-Only memory stream */
49
50/* RWops status, set by a read or write operation */
51#define SDL_RWOPS_STATUS_READY 0 /**< Everything is ready */
52#define SDL_RWOPS_STATUS_ERROR 1 /**< Read or write I/O error */
53#define SDL_RWOPS_STATUS_EOF 2 /**< End of file */
54#define SDL_RWOPS_STATUS_NOT_READY 3 /**< Non blocking I/O, not ready */
55#define SDL_RWOPS_STATUS_READONLY 4 /**< Tried to write a read-only buffer */
56#define SDL_RWOPS_STATUS_WRITEONLY 5 /**< Tried to read a write-only buffer */
57
58/**
59 * This is the read/write operation structure -- very basic.
60 */
61typedef struct SDL_RWops
62{
63 /**
64 * Return the number of bytes in this rwops
65 *
66 * \return the total size of the data stream, or -1 on error.
67 */
68 Sint64 (SDLCALL *size)(struct SDL_RWops *context);
69
70 /**
71 * Seek to \c offset relative to \c whence, one of stdio's whence values:
72 * SDL_RW_SEEK_SET, SDL_RW_SEEK_CUR, SDL_RW_SEEK_END
73 *
74 * \return the final offset in the data stream, or -1 on error.
75 */
76 Sint64 (SDLCALL *seek)(struct SDL_RWops *context, Sint64 offset, int whence);
77
78 /**
79 * Read up to \c size bytes from the data stream to the area pointed
80 * at by \c ptr.
81 *
82 * \return the number of bytes read
83 */
84 size_t (SDLCALL *read)(struct SDL_RWops *context, void *ptr, size_t size);
85
86 /**
87 * Write exactly \c size bytes from the area pointed at by \c ptr
88 * to data stream.
89 *
90 * \return the number of bytes written
91 */
92 size_t (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, size_t size);
93
94 /**
95 * Close and free an allocated SDL_RWops structure.
96 *
97 * \return 0 if successful or -1 on write error when flushing data.
98 */
99 int (SDLCALL *close)(struct SDL_RWops *context);
100
104 union
105 {
106#ifdef __ANDROID__
107 struct
108 {
109 void *asset;
110 } androidio;
111
112#elif defined(__WIN32__) || defined(__GDK__) || defined(__WINRT__)
113 struct
114 {
115 SDL_bool append;
116 void *h;
117 struct
118 {
119 void *data;
120 size_t size;
121 size_t left;
122 } buffer;
123 } windowsio;
124#endif
125
126 struct
127 {
129 void *fp;
131
132 struct
133 {
138
139 struct
140 {
141 void *data1;
142 void *data2;
145
146} SDL_RWops;
147
148
149/**
150 * \name RWFrom functions
151 *
152 * Functions to create SDL_RWops structures from various data streams.
153 */
154/* @{ */
155
156/**
157 * Use this function to create a new SDL_RWops structure for reading from
158 * and/or writing to a named file.
159 *
160 * The `mode` string is treated roughly the same as in a call to the C
161 * library's fopen(), even if SDL doesn't happen to use fopen() behind the
162 * scenes.
163 *
164 * Available `mode` strings:
165 *
166 * - "r": Open a file for reading. The file must exist.
167 * - "w": Create an empty file for writing. If a file with the same name
168 * already exists its content is erased and the file is treated as a new
169 * empty file.
170 * - "a": Append to a file. Writing operations append data at the end of the
171 * file. The file is created if it does not exist.
172 * - "r+": Open a file for update both reading and writing. The file must
173 * exist.
174 * - "w+": Create an empty file for both reading and writing. If a file with
175 * the same name already exists its content is erased and the file is
176 * treated as a new empty file.
177 * - "a+": Open a file for reading and appending. All writing operations are
178 * performed at the end of the file, protecting the previous content to be
179 * overwritten. You can reposition (fseek, rewind) the internal pointer to
180 * anywhere in the file for reading, but writing operations will move it
181 * back to the end of file. The file is created if it does not exist.
182 *
183 * **NOTE**: In order to open a file as a binary file, a "b" character has to
184 * be included in the `mode` string. This additional "b" character can either
185 * be appended at the end of the string (thus making the following compound
186 * modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the
187 * letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").
188 * Additional characters may follow the sequence, although they should have no
189 * effect. For example, "t" is sometimes appended to make explicit the file is
190 * a text file.
191 *
192 * This function supports Unicode filenames, but they must be encoded in UTF-8
193 * format, regardless of the underlying operating system.
194 *
195 * As a fallback, SDL_RWFromFile() will transparently open a matching filename
196 * in an Android app's `assets`.
197 *
198 * Closing the SDL_RWops will close the file handle SDL is holding internally.
199 *
200 * \param file a UTF-8 string representing the filename to open
201 * \param mode an ASCII string representing the mode to be used for opening
202 * the file.
203 * \returns a pointer to the SDL_RWops structure that is created, or NULL on
204 * failure; call SDL_GetError() for more information.
205 *
206 * \since This function is available since SDL 3.0.0.
207 *
208 * \sa SDL_RWclose
209 * \sa SDL_RWFromConstMem
210 * \sa SDL_RWFromMem
211 * \sa SDL_RWread
212 * \sa SDL_RWseek
213 * \sa SDL_RWtell
214 * \sa SDL_RWwrite
215 */
216extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file, const char *mode);
217
218/**
219 * Use this function to prepare a read-write memory buffer for use with
220 * SDL_RWops.
221 *
222 * This function sets up an SDL_RWops struct based on a memory area of a
223 * certain size, for both read and write access.
224 *
225 * This memory buffer is not copied by the RWops; the pointer you provide must
226 * remain valid until you close the stream. Closing the stream will not free
227 * the original buffer.
228 *
229 * If you need to make sure the RWops never writes to the memory buffer, you
230 * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
231 *
232 * \param mem a pointer to a buffer to feed an SDL_RWops stream
233 * \param size the buffer size, in bytes
234 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
235 * SDL_GetError() for more information.
236 *
237 * \since This function is available since SDL 3.0.0.
238 *
239 * \sa SDL_RWclose
240 * \sa SDL_RWFromConstMem
241 * \sa SDL_RWFromFile
242 * \sa SDL_RWFromMem
243 * \sa SDL_RWread
244 * \sa SDL_RWseek
245 * \sa SDL_RWtell
246 * \sa SDL_RWwrite
247 */
248extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, size_t size);
249
250/**
251 * Use this function to prepare a read-only memory buffer for use with RWops.
252 *
253 * This function sets up an SDL_RWops struct based on a memory area of a
254 * certain size. It assumes the memory area is not writable.
255 *
256 * Attempting to write to this RWops stream will report an error without
257 * writing to the memory buffer.
258 *
259 * This memory buffer is not copied by the RWops; the pointer you provide must
260 * remain valid until you close the stream. Closing the stream will not free
261 * the original buffer.
262 *
263 * If you need to write to a memory buffer, you should use SDL_RWFromMem()
264 * with a writable buffer of memory instead.
265 *
266 * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream
267 * \param size the buffer size, in bytes
268 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
269 * SDL_GetError() for more information.
270 *
271 * \since This function is available since SDL 3.0.0.
272 *
273 * \sa SDL_RWclose
274 * \sa SDL_RWFromConstMem
275 * \sa SDL_RWFromFile
276 * \sa SDL_RWFromMem
277 * \sa SDL_RWread
278 * \sa SDL_RWseek
279 * \sa SDL_RWtell
280 */
281extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem, size_t size);
282
283/* @} *//* RWFrom functions */
284
285
286/**
287 * Use this function to allocate an empty, unpopulated SDL_RWops structure.
288 *
289 * Applications do not need to use this function unless they are providing
290 * their own SDL_RWops implementation. If you just need an SDL_RWops to
291 * read/write a common data source, you should use the built-in
292 * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc.
293 *
294 * You must free the returned pointer with SDL_DestroyRW(). Depending on your
295 * operating system and compiler, there may be a difference between the
296 * malloc() and free() your program uses and the versions SDL calls
297 * internally. Trying to mix the two can cause crashing such as segmentation
298 * faults. Since all SDL_RWops must free themselves when their **close**
299 * method is called, all SDL_RWops must be allocated through this function, so
300 * they can all be freed correctly with SDL_DestroyRW().
301 *
302 * \returns a pointer to the allocated memory on success, or NULL on failure;
303 * call SDL_GetError() for more information.
304 *
305 * \since This function is available since SDL 3.0.0.
306 *
307 * \sa SDL_DestroyRW
308 */
309extern DECLSPEC SDL_RWops *SDLCALL SDL_CreateRW(void);
310
311/**
312 * Use this function to free an SDL_RWops structure allocated by
313 * SDL_CreateRW().
314 *
315 * Applications do not need to use this function unless they are providing
316 * their own SDL_RWops implementation. If you just need an SDL_RWops to
317 * read/write a common data source, you should use the built-in
318 * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and
319 * call the **close** method on those SDL_RWops pointers when you are done
320 * with them.
321 *
322 * Only use SDL_DestroyRW() on pointers returned by SDL_CreateRW(). The
323 * pointer is invalid as soon as this function returns. Any extra memory
324 * allocated during creation of the SDL_RWops is not freed by SDL_DestroyRW();
325 * the programmer must be responsible for managing that memory in their
326 * **close** method.
327 *
328 * \param context the SDL_RWops structure to be freed
329 *
330 * \since This function is available since SDL 3.0.0.
331 *
332 * \sa SDL_CreateRW
333 */
334extern DECLSPEC void SDLCALL SDL_DestroyRW(SDL_RWops *context);
335
336/**
337 * Get the properties associated with an SDL_RWops.
338 *
339 * \param context a pointer to an SDL_RWops structure
340 * \returns a valid property ID on success or 0 on failure; call
341 * SDL_GetError() for more information.
342 *
343 * \since This function is available since SDL 3.0.0.
344 *
345 * \sa SDL_GetProperty
346 * \sa SDL_SetProperty
347 */
348extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRWProperties(SDL_RWops *context);
349
350#define SDL_RW_SEEK_SET 0 /**< Seek from the beginning of data */
351#define SDL_RW_SEEK_CUR 1 /**< Seek relative to current read point */
352#define SDL_RW_SEEK_END 2 /**< Seek relative to the end of data */
353
354/**
355 * Use this function to get the size of the data stream in an SDL_RWops.
356 *
357 * \param context the SDL_RWops to get the size of the data stream from
358 * \returns the size of the data stream in the SDL_RWops on success or a
359 * negative error code on failure; call SDL_GetError() for more
360 * information.
361 *
362 * \since This function is available since SDL 3.0.0.
363 */
364extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
365
366/**
367 * Seek within an SDL_RWops data stream.
368 *
369 * This function seeks to byte `offset`, relative to `whence`.
370 *
371 * `whence` may be any of the following values:
372 *
373 * - `SDL_RW_SEEK_SET`: seek from the beginning of data
374 * - `SDL_RW_SEEK_CUR`: seek relative to current read point
375 * - `SDL_RW_SEEK_END`: seek relative to the end of data
376 *
377 * If this stream can not seek, it will return -1.
378 *
379 * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
380 * `seek` method appropriately, to simplify application development.
381 *
382 * \param context a pointer to an SDL_RWops structure
383 * \param offset an offset in bytes, relative to **whence** location; can be
384 * negative
385 * \param whence any of `SDL_RW_SEEK_SET`, `SDL_RW_SEEK_CUR`,
386 * `SDL_RW_SEEK_END`
387 * \returns the final offset in the data stream after the seek or a negative
388 * error code on failure; call SDL_GetError() for more information.
389 *
390 * \since This function is available since SDL 3.0.0.
391 *
392 * \sa SDL_RWclose
393 * \sa SDL_RWFromConstMem
394 * \sa SDL_RWFromFile
395 * \sa SDL_RWFromMem
396 * \sa SDL_RWread
397 * \sa SDL_RWtell
398 * \sa SDL_RWwrite
399 */
400extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context, Sint64 offset, int whence);
401
402/**
403 * Determine the current read/write offset in an SDL_RWops data stream.
404 *
405 * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
406 * method, with an offset of 0 bytes from `SDL_RW_SEEK_CUR`, to simplify
407 * application development.
408 *
409 * \param context an SDL_RWops data stream object from which to get the
410 * current offset
411 * \returns the current offset in the stream, or -1 if the information can not
412 * be determined.
413 *
414 * \since This function is available since SDL 3.0.0.
415 *
416 * \sa SDL_RWclose
417 * \sa SDL_RWFromConstMem
418 * \sa SDL_RWFromFile
419 * \sa SDL_RWFromMem
420 * \sa SDL_RWread
421 * \sa SDL_RWseek
422 * \sa SDL_RWwrite
423 */
424extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
425
426/**
427 * Read from a data source.
428 *
429 * This function reads up `size` bytes from the data source to the area
430 * pointed at by `ptr`. This function may read less bytes than requested. It
431 * will return zero when the data stream is completely read, or -1 on error.
432 * For streams that support non-blocking operation, if nothing was read
433 * because it would require blocking, this function returns -2 to distinguish
434 * that this is not an error or end-of-file, and the caller can try again
435 * later.
436 *
437 * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
438 * `read` method appropriately, to simplify application development.
439 *
440 * It is an error to specify a negative `size`, but this parameter is signed
441 * so you definitely cannot overflow the return value on a successful run with
442 * enormous amounts of data.
443 *
444 * \param context a pointer to an SDL_RWops structure
445 * \param ptr a pointer to a buffer to read data into
446 * \param size the number of bytes to read from the data source.
447 * \returns the number of bytes read, or 0 on end of file or other error.
448 *
449 * \since This function is available since SDL 3.0.0.
450 *
451 * \sa SDL_RWclose
452 * \sa SDL_RWFromConstMem
453 * \sa SDL_RWFromFile
454 * \sa SDL_RWFromMem
455 * \sa SDL_RWseek
456 * \sa SDL_RWwrite
457 */
458extern DECLSPEC size_t SDLCALL SDL_RWread(SDL_RWops *context, void *ptr, size_t size);
459
460/**
461 * Write to an SDL_RWops data stream.
462 *
463 * This function writes exactly `size` bytes from the area pointed at by `ptr`
464 * to the stream. If this fails for any reason, it'll return less than `size`
465 * to demonstrate how far the write progressed. On success, it returns `num`.
466 *
467 * On error, this function still attempts to write as much as possible, so it
468 * might return a positive value less than the requested write size. If the
469 * function failed to write anything and there was an actual error, it will
470 * return -1. For streams that support non-blocking operation, if nothing was
471 * written because it would require blocking, this function returns -2 to
472 * distinguish that this is not an error and the caller can try again later.
473 *
474 * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
475 * `write` method appropriately, to simplify application development.
476 *
477 * It is an error to specify a negative `size`, but this parameter is signed
478 * so you definitely cannot overflow the return value on a successful run with
479 * enormous amounts of data.
480 *
481 * \param context a pointer to an SDL_RWops structure
482 * \param ptr a pointer to a buffer containing data to write
483 * \param size the number of bytes to write
484 * \returns the number of bytes written, which will be less than `num` on
485 * error; call SDL_GetError() for more information.
486 *
487 * \since This function is available since SDL 3.0.0.
488 *
489 * \sa SDL_RWclose
490 * \sa SDL_RWFromConstMem
491 * \sa SDL_RWFromFile
492 * \sa SDL_RWFromMem
493 * \sa SDL_RWprint
494 * \sa SDL_RWread
495 * \sa SDL_RWseek
496 */
497extern DECLSPEC size_t SDLCALL SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size);
498
499/**
500 * Print to an SDL_RWops data stream.
501 *
502 * This function does formatted printing to the stream.
503 *
504 * \param context a pointer to an SDL_RWops structure
505 * \param fmt a printf() style format string
506 * \param ... additional parameters matching % tokens in the `fmt` string, if
507 * any
508 * \returns the number of bytes written, or 0 on error; call SDL_GetError()
509 * for more information.
510 *
511 * \since This function is available since SDL 3.0.0.
512 *
513 * \sa SDL_RWclose
514 * \sa SDL_RWFromConstMem
515 * \sa SDL_RWFromFile
516 * \sa SDL_RWFromMem
517 * \sa SDL_RWread
518 * \sa SDL_RWseek
519 * \sa SDL_RWwrite
520 */
521extern DECLSPEC size_t SDLCALL SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
522
523/**
524 * Print to an SDL_RWops data stream.
525 *
526 * This function does formatted printing to the stream.
527 *
528 * \param context a pointer to an SDL_RWops structure
529 * \param fmt a printf() style format string
530 * \param ap a variable argument list
531 * \returns the number of bytes written, or 0 on error; call SDL_GetError()
532 * for more information.
533 *
534 * \since This function is available since SDL 3.0.0.
535 *
536 * \sa SDL_RWclose
537 * \sa SDL_RWFromConstMem
538 * \sa SDL_RWFromFile
539 * \sa SDL_RWFromMem
540 * \sa SDL_RWread
541 * \sa SDL_RWseek
542 * \sa SDL_RWwrite
543 */
544extern DECLSPEC size_t SDLCALL SDL_RWvprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
545
546/**
547 * Close and free an allocated SDL_RWops structure.
548 *
549 * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
550 * resources used by the stream and frees the SDL_RWops itself with
551 * SDL_DestroyRW(). This returns 0 on success, or -1 if the stream failed to
552 * flush to its output (e.g. to disk).
553 *
554 * Note that if this fails to flush the stream to disk, this function reports
555 * an error, but the SDL_RWops is still invalid once this function returns.
556 *
557 * \param context SDL_RWops structure to close
558 * \returns 0 on success or a negative error code on failure; call
559 * SDL_GetError() for more information.
560 *
561 * \since This function is available since SDL 3.0.0.
562 *
563 * \sa SDL_RWFromConstMem
564 * \sa SDL_RWFromFile
565 * \sa SDL_RWFromMem
566 * \sa SDL_RWread
567 * \sa SDL_RWseek
568 * \sa SDL_RWwrite
569 */
570extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
571
572/**
573 * Load all the data from an SDL data stream.
574 *
575 * The data is allocated with a zero byte at the end (null terminated) for
576 * convenience. This extra byte is not included in the value reported via
577 * `datasize`.
578 *
579 * The data should be freed with SDL_free().
580 *
581 * \param src the SDL_RWops to read all available data from
582 * \param datasize if not NULL, will store the number of bytes read
583 * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
584 * even in the case of an error
585 * \returns the data, or NULL if there was an error.
586 *
587 * \since This function is available since SDL 3.0.0.
588 */
589extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc);
590
591/**
592 * Load all the data from a file path.
593 *
594 * The data is allocated with a zero byte at the end (null terminated) for
595 * convenience. This extra byte is not included in the value reported via
596 * `datasize`.
597 *
598 * The data should be freed with SDL_free().
599 *
600 * \param file the path to read all available data from
601 * \param datasize if not NULL, will store the number of bytes read
602 * \returns the data, or NULL if there was an error.
603 *
604 * \since This function is available since SDL 3.0.0.
605 */
606extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
607
608/**
609 * \name Read endian functions
610 *
611 * Read an item of the specified endianness and return in native format.
612 */
613/* @{ */
614
615/**
616 * Use this function to read a byte from an SDL_RWops.
617 *
618 * \param src the SDL_RWops to read from
619 * \param value a pointer filled in with the data read
620 * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
621 * for more information.
622 *
623 * \since This function is available since SDL 3.0.0.
624 */
625extern DECLSPEC SDL_bool SDLCALL SDL_ReadU8(SDL_RWops *src, Uint8 *value);
626
627/**
628 * Use this function to read 16 bits of little-endian data from an SDL_RWops
629 * and return in native format.
630 *
631 * SDL byteswaps the data only if necessary, so the data returned will be in
632 * the native byte order.
633 *
634 * \param src the stream from which to read data
635 * \param value a pointer filled in with the data read
636 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
637 * SDL_GetError() for more information.
638 *
639 * \since This function is available since SDL 3.0.0.
640 */
641extern DECLSPEC SDL_bool SDLCALL SDL_ReadU16LE(SDL_RWops *src, Uint16 *value);
642
643/**
644 * Use this function to read 16 bits of little-endian data from an SDL_RWops
645 * and return in native format.
646 *
647 * SDL byteswaps the data only if necessary, so the data returned will be in
648 * the native byte order.
649 *
650 * \param src the stream from which to read data
651 * \param value a pointer filled in with the data read
652 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
653 * SDL_GetError() for more information.
654 *
655 * \since This function is available since SDL 3.0.0.
656 */
657extern DECLSPEC SDL_bool SDLCALL SDL_ReadS16LE(SDL_RWops *src, Sint16 *value);
658
659/**
660 * Use this function to read 16 bits of big-endian data from an SDL_RWops and
661 * return in native format.
662 *
663 * SDL byteswaps the data only if necessary, so the data returned will be in
664 * the native byte order.
665 *
666 * \param src the stream from which to read data
667 * \param value a pointer filled in with the data read
668 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
669 * SDL_GetError() for more information.
670 *
671 * \since This function is available since SDL 3.0.0.
672 */
673extern DECLSPEC SDL_bool SDLCALL SDL_ReadU16BE(SDL_RWops *src, Uint16 *value);
674
675/**
676 * Use this function to read 16 bits of big-endian data from an SDL_RWops and
677 * return in native format.
678 *
679 * SDL byteswaps the data only if necessary, so the data returned will be in
680 * the native byte order.
681 *
682 * \param src the stream from which to read data
683 * \param value a pointer filled in with the data read
684 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
685 * SDL_GetError() for more information.
686 *
687 * \since This function is available since SDL 3.0.0.
688 */
689extern DECLSPEC SDL_bool SDLCALL SDL_ReadS16BE(SDL_RWops *src, Sint16 *value);
690
691/**
692 * Use this function to read 32 bits of little-endian data from an SDL_RWops
693 * and return in native format.
694 *
695 * SDL byteswaps the data only if necessary, so the data returned will be in
696 * the native byte order.
697 *
698 * \param src the stream from which to read data
699 * \param value a pointer filled in with the data read
700 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
701 * SDL_GetError() for more information.
702 *
703 * \since This function is available since SDL 3.0.0.
704 */
705extern DECLSPEC SDL_bool SDLCALL SDL_ReadU32LE(SDL_RWops *src, Uint32 *value);
706
707/**
708 * Use this function to read 32 bits of little-endian data from an SDL_RWops
709 * and return in native format.
710 *
711 * SDL byteswaps the data only if necessary, so the data returned will be in
712 * the native byte order.
713 *
714 * \param src the stream from which to read data
715 * \param value a pointer filled in with the data read
716 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
717 * SDL_GetError() for more information.
718 *
719 * \since This function is available since SDL 3.0.0.
720 */
721extern DECLSPEC SDL_bool SDLCALL SDL_ReadS32LE(SDL_RWops *src, Sint32 *value);
722
723/**
724 * Use this function to read 32 bits of big-endian data from an SDL_RWops and
725 * return in native format.
726 *
727 * SDL byteswaps the data only if necessary, so the data returned will be in
728 * the native byte order.
729 *
730 * \param src the stream from which to read data
731 * \param value a pointer filled in with the data read
732 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
733 * SDL_GetError() for more information.
734 *
735 * \since This function is available since SDL 3.0.0.
736 */
737extern DECLSPEC SDL_bool SDLCALL SDL_ReadU32BE(SDL_RWops *src, Uint32 *value);
738
739/**
740 * Use this function to read 32 bits of big-endian data from an SDL_RWops and
741 * return in native format.
742 *
743 * SDL byteswaps the data only if necessary, so the data returned will be in
744 * the native byte order.
745 *
746 * \param src the stream from which to read data
747 * \param value a pointer filled in with the data read
748 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
749 * SDL_GetError() for more information.
750 *
751 * \since This function is available since SDL 3.0.0.
752 */
753extern DECLSPEC SDL_bool SDLCALL SDL_ReadS32BE(SDL_RWops *src, Sint32 *value);
754
755/**
756 * Use this function to read 64 bits of little-endian data from an SDL_RWops
757 * and return in native format.
758 *
759 * SDL byteswaps the data only if necessary, so the data returned will be in
760 * the native byte order.
761 *
762 * \param src the stream from which to read data
763 * \param value a pointer filled in with the data read
764 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
765 * SDL_GetError() for more information.
766 *
767 * \since This function is available since SDL 3.0.0.
768 */
769extern DECLSPEC SDL_bool SDLCALL SDL_ReadU64LE(SDL_RWops *src, Uint64 *value);
770
771/**
772 * Use this function to read 64 bits of little-endian data from an SDL_RWops
773 * and return in native format.
774 *
775 * SDL byteswaps the data only if necessary, so the data returned will be in
776 * the native byte order.
777 *
778 * \param src the stream from which to read data
779 * \param value a pointer filled in with the data read
780 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
781 * SDL_GetError() for more information.
782 *
783 * \since This function is available since SDL 3.0.0.
784 */
785extern DECLSPEC SDL_bool SDLCALL SDL_ReadS64LE(SDL_RWops *src, Sint64 *value);
786
787/**
788 * Use this function to read 64 bits of big-endian data from an SDL_RWops and
789 * return in native format.
790 *
791 * SDL byteswaps the data only if necessary, so the data returned will be in
792 * the native byte order.
793 *
794 * \param src the stream from which to read data
795 * \param value a pointer filled in with the data read
796 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
797 * SDL_GetError() for more information.
798 *
799 * \since This function is available since SDL 3.0.0.
800 */
801extern DECLSPEC SDL_bool SDLCALL SDL_ReadU64BE(SDL_RWops *src, Uint64 *value);
802
803/**
804 * Use this function to read 64 bits of big-endian data from an SDL_RWops and
805 * return in native format.
806 *
807 * SDL byteswaps the data only if necessary, so the data returned will be in
808 * the native byte order.
809 *
810 * \param src the stream from which to read data
811 * \param value a pointer filled in with the data read
812 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
813 * SDL_GetError() for more information.
814 *
815 * \since This function is available since SDL 3.0.0.
816 */
817extern DECLSPEC SDL_bool SDLCALL SDL_ReadS64BE(SDL_RWops *src, Sint64 *value);
818/* @} *//* Read endian functions */
819
820/**
821 * \name Write endian functions
822 *
823 * Write an item of native format to the specified endianness.
824 */
825/* @{ */
826
827/**
828 * Use this function to write a byte to an SDL_RWops.
829 *
830 * \param dst the SDL_RWops to write to
831 * \param value the byte value to write
832 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
833 * SDL_GetError() for more information.
834 *
835 * \since This function is available since SDL 3.0.0.
836 */
837extern DECLSPEC SDL_bool SDLCALL SDL_WriteU8(SDL_RWops *dst, Uint8 value);
838
839/**
840 * Use this function to write 16 bits in native format to an SDL_RWops as
841 * little-endian data.
842 *
843 * SDL byteswaps the data only if necessary, so the application always
844 * specifies native format, and the data written will be in little-endian
845 * format.
846 *
847 * \param dst the stream to which data will be written
848 * \param value the data to be written, in native format
849 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
850 * SDL_GetError() for more information.
851 *
852 * \since This function is available since SDL 3.0.0.
853 */
854extern DECLSPEC SDL_bool SDLCALL SDL_WriteU16LE(SDL_RWops *dst, Uint16 value);
855
856/**
857 * Use this function to write 16 bits in native format to an SDL_RWops as
858 * little-endian data.
859 *
860 * SDL byteswaps the data only if necessary, so the application always
861 * specifies native format, and the data written will be in little-endian
862 * format.
863 *
864 * \param dst the stream to which data will be written
865 * \param value the data to be written, in native format
866 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
867 * SDL_GetError() for more information.
868 *
869 * \since This function is available since SDL 3.0.0.
870 */
871extern DECLSPEC SDL_bool SDLCALL SDL_WriteS16LE(SDL_RWops *dst, Sint16 value);
872
873/**
874 * Use this function to write 16 bits in native format to an SDL_RWops as
875 * big-endian data.
876 *
877 * SDL byteswaps the data only if necessary, so the application always
878 * specifies native format, and the data written will be in big-endian format.
879 *
880 * \param dst the stream to which data will be written
881 * \param value the data to be written, in native format
882 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
883 * SDL_GetError() for more information.
884 *
885 * \since This function is available since SDL 3.0.0.
886 */
887extern DECLSPEC SDL_bool SDLCALL SDL_WriteU16BE(SDL_RWops *dst, Uint16 value);
888
889/**
890 * Use this function to write 16 bits in native format to an SDL_RWops as
891 * big-endian data.
892 *
893 * SDL byteswaps the data only if necessary, so the application always
894 * specifies native format, and the data written will be in big-endian format.
895 *
896 * \param dst the stream to which data will be written
897 * \param value the data to be written, in native format
898 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
899 * SDL_GetError() for more information.
900 *
901 * \since This function is available since SDL 3.0.0.
902 */
903extern DECLSPEC SDL_bool SDLCALL SDL_WriteS16BE(SDL_RWops *dst, Sint16 value);
904
905/**
906 * Use this function to write 32 bits in native format to an SDL_RWops as
907 * little-endian data.
908 *
909 * SDL byteswaps the data only if necessary, so the application always
910 * specifies native format, and the data written will be in little-endian
911 * format.
912 *
913 * \param dst the stream to which data will be written
914 * \param value the data to be written, in native format
915 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
916 * SDL_GetError() for more information.
917 *
918 * \since This function is available since SDL 3.0.0.
919 */
920extern DECLSPEC SDL_bool SDLCALL SDL_WriteU32LE(SDL_RWops *dst, Uint32 value);
921
922/**
923 * Use this function to write 32 bits in native format to an SDL_RWops as
924 * little-endian data.
925 *
926 * SDL byteswaps the data only if necessary, so the application always
927 * specifies native format, and the data written will be in little-endian
928 * format.
929 *
930 * \param dst the stream to which data will be written
931 * \param value the data to be written, in native format
932 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
933 * SDL_GetError() for more information.
934 *
935 * \since This function is available since SDL 3.0.0.
936 */
937extern DECLSPEC SDL_bool SDLCALL SDL_WriteS32LE(SDL_RWops *dst, Sint32 value);
938
939/**
940 * Use this function to write 32 bits in native format to an SDL_RWops as
941 * big-endian data.
942 *
943 * SDL byteswaps the data only if necessary, so the application always
944 * specifies native format, and the data written will be in big-endian format.
945 *
946 * \param dst the stream to which data will be written
947 * \param value the data to be written, in native format
948 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
949 * SDL_GetError() for more information.
950 *
951 * \since This function is available since SDL 3.0.0.
952 */
953extern DECLSPEC SDL_bool SDLCALL SDL_WriteU32BE(SDL_RWops *dst, Uint32 value);
954
955/**
956 * Use this function to write 32 bits in native format to an SDL_RWops as
957 * big-endian data.
958 *
959 * SDL byteswaps the data only if necessary, so the application always
960 * specifies native format, and the data written will be in big-endian format.
961 *
962 * \param dst the stream to which data will be written
963 * \param value the data to be written, in native format
964 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
965 * SDL_GetError() for more information.
966 *
967 * \since This function is available since SDL 3.0.0.
968 */
969extern DECLSPEC SDL_bool SDLCALL SDL_WriteS32BE(SDL_RWops *dst, Sint32 value);
970
971/**
972 * Use this function to write 64 bits in native format to an SDL_RWops as
973 * little-endian data.
974 *
975 * SDL byteswaps the data only if necessary, so the application always
976 * specifies native format, and the data written will be in little-endian
977 * format.
978 *
979 * \param dst the stream to which data will be written
980 * \param value the data to be written, in native format
981 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
982 * SDL_GetError() for more information.
983 *
984 * \since This function is available since SDL 3.0.0.
985 */
986extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64LE(SDL_RWops *dst, Uint64 value);
987
988/**
989 * Use this function to write 64 bits in native format to an SDL_RWops as
990 * little-endian data.
991 *
992 * SDL byteswaps the data only if necessary, so the application always
993 * specifies native format, and the data written will be in little-endian
994 * format.
995 *
996 * \param dst the stream to which data will be written
997 * \param value the data to be written, in native format
998 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
999 * SDL_GetError() for more information.
1000 *
1001 * \since This function is available since SDL 3.0.0.
1002 */
1003extern DECLSPEC SDL_bool SDLCALL SDL_WriteS64LE(SDL_RWops *dst, Sint64 value);
1004
1005/**
1006 * Use this function to write 64 bits in native format to an SDL_RWops as
1007 * big-endian data.
1008 *
1009 * SDL byteswaps the data only if necessary, so the application always
1010 * specifies native format, and the data written will be in big-endian format.
1011 *
1012 * \param dst the stream to which data will be written
1013 * \param value the data to be written, in native format
1014 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
1015 * SDL_GetError() for more information.
1016 *
1017 * \since This function is available since SDL 3.0.0.
1018 */
1019extern DECLSPEC SDL_bool SDLCALL SDL_WriteU64BE(SDL_RWops *dst, Uint64 value);
1020
1021/**
1022 * Use this function to write 64 bits in native format to an SDL_RWops as
1023 * big-endian data.
1024 *
1025 * SDL byteswaps the data only if necessary, so the application always
1026 * specifies native format, and the data written will be in big-endian format.
1027 *
1028 * \param dst the stream to which data will be written
1029 * \param value the data to be written, in native format
1030 * \returns SDL_TRUE on successful write, SDL_FALSE on failure; call
1031 * SDL_GetError() for more information.
1032 *
1033 * \since This function is available since SDL 3.0.0.
1034 */
1035extern DECLSPEC SDL_bool SDLCALL SDL_WriteS64BE(SDL_RWops *dst, Sint64 value);
1036
1037/* @} *//* Write endian functions */
1038
1039/* Ends C function definitions when using C++ */
1040#ifdef __cplusplus
1041}
1042#endif
1043#include <SDL3/SDL_close_code.h>
1044
1045#endif /* SDL_rwops_h_ */
Uint32 SDL_PropertiesID
SDL_bool SDL_ReadU32BE(SDL_RWops *src, Uint32 *value)
SDL_bool SDL_WriteS64BE(SDL_RWops *dst, Sint64 value)
SDL_bool SDL_ReadU16BE(SDL_RWops *src, Uint16 *value)
SDL_bool SDL_WriteU64LE(SDL_RWops *dst, Uint64 value)
void SDL_DestroyRW(SDL_RWops *context)
SDL_bool SDL_ReadU64LE(SDL_RWops *src, Uint64 *value)
Sint64 SDL_RWsize(SDL_RWops *context)
SDL_bool SDL_ReadU8(SDL_RWops *src, Uint8 *value)
SDL_RWops * SDL_RWFromMem(void *mem, size_t size)
SDL_bool SDL_WriteU16BE(SDL_RWops *dst, Uint16 value)
SDL_bool SDL_ReadU16LE(SDL_RWops *src, Uint16 *value)
SDL_bool SDL_ReadS64LE(SDL_RWops *src, Sint64 *value)
void * SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
SDL_bool SDL_ReadU32LE(SDL_RWops *src, Uint32 *value)
SDL_bool SDL_WriteU16LE(SDL_RWops *dst, Uint16 value)
SDL_RWops * SDL_RWFromFile(const char *file, const char *mode)
size_t SDL_RWread(SDL_RWops *context, void *ptr, size_t size)
SDL_bool SDL_WriteS32BE(SDL_RWops *dst, Sint32 value)
Sint64 SDL_RWseek(SDL_RWops *context, Sint64 offset, int whence)
SDL_bool SDL_WriteU8(SDL_RWops *dst, Uint8 value)
SDL_bool SDL_WriteS16LE(SDL_RWops *dst, Sint16 value)
SDL_bool SDL_ReadS16BE(SDL_RWops *src, Sint16 *value)
SDL_bool SDL_ReadS16LE(SDL_RWops *src, Sint16 *value)
SDL_bool SDL_ReadS64BE(SDL_RWops *src, Sint64 *value)
size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size)
Sint64 SDL_RWtell(SDL_RWops *context)
SDL_bool SDL_ReadU64BE(SDL_RWops *src, Uint64 *value)
SDL_bool SDL_WriteU32LE(SDL_RWops *dst, Uint32 value)
SDL_bool SDL_WriteU64BE(SDL_RWops *dst, Uint64 value)
SDL_bool SDL_ReadS32BE(SDL_RWops *src, Sint32 *value)
SDL_bool SDL_WriteS32LE(SDL_RWops *dst, Sint32 value)
size_t SDL_RWvprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
SDL_PropertiesID SDL_GetRWProperties(SDL_RWops *context)
SDL_bool SDL_WriteS16BE(SDL_RWops *dst, Sint16 value)
SDL_RWops * SDL_RWFromConstMem(const void *mem, size_t size)
SDL_bool SDL_ReadS32LE(SDL_RWops *src, Sint32 *value)
SDL_RWops * SDL_CreateRW(void)
int SDL_RWclose(SDL_RWops *context)
SDL_bool SDL_WriteS64LE(SDL_RWops *dst, Sint64 value)
void * SDL_LoadFile(const char *file, size_t *datasize)
SDL_bool SDL_WriteU32BE(SDL_RWops *dst, Uint32 value)
size_t SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
uint8_t Uint8
Definition SDL_stdinc.h:149
int64_t Sint64
Definition SDL_stdinc.h:180
uint16_t Uint16
Definition SDL_stdinc.h:161
#define SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
Definition SDL_stdinc.h:327
int32_t Sint32
Definition SDL_stdinc.h:167
unsigned int SDL_bool
Definition SDL_stdinc.h:136
SDL_MALLOC size_t size
Definition SDL_stdinc.h:399
int16_t Sint16
Definition SDL_stdinc.h:155
#define SDL_PRINTF_FORMAT_STRING
Definition SDL_stdinc.h:315
#define SDL_PRINTF_VARARG_FUNC(fmtargnumber)
Definition SDL_stdinc.h:326
uint64_t Uint64
Definition SDL_stdinc.h:186
uint32_t Uint32
Definition SDL_stdinc.h:173
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size)
Definition SDL_rwops.h:84
Uint32 type
Definition SDL_rwops.h:101
SDL_bool autoclose
Definition SDL_rwops.h:128
Uint32 status
Definition SDL_rwops.h:102
Uint8 * stop
Definition SDL_rwops.h:136
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size)
Definition SDL_rwops.h:92
Uint8 * here
Definition SDL_rwops.h:135
struct SDL_RWops::@5::@7 mem
struct SDL_RWops::@5::@8 unknown
SDL_PropertiesID props
Definition SDL_rwops.h:103
int(* close)(struct SDL_RWops *context)
Definition SDL_rwops.h:99
union SDL_RWops::@5 hidden
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition SDL_rwops.h:76
struct SDL_RWops::@5::@6 stdio
void * fp
Definition SDL_rwops.h:129
void * data1
Definition SDL_rwops.h:141
Sint64(* size)(struct SDL_RWops *context)
Definition SDL_rwops.h:68
void * data2
Definition SDL_rwops.h:142
Uint8 * base
Definition SDL_rwops.h:134