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