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 0U /**< Unknown stream type */
43#define SDL_RWOPS_WINFILE 1U /**< Win32 file */
44#define SDL_RWOPS_STDFILE 2U /**< Stdio file */
45#define SDL_RWOPS_JNIFILE 3U /**< Android asset */
46#define SDL_RWOPS_MEMORY 4U /**< Memory stream */
47#define SDL_RWOPS_MEMORY_RO 5U /**< Read-Only memory stream */
48
49/**
50 * This is the read/write operation structure -- very basic.
51 */
52typedef struct SDL_RWops
53{
54 /**
55 * Return the size of the file in this rwops, or -1 if unknown
56 */
57 Sint64 (SDLCALL * size) (struct SDL_RWops * context);
58
59 /**
60 * Seek to \c offset relative to \c whence, one of stdio's whence values:
61 * SDL_RW_SEEK_SET, SDL_RW_SEEK_CUR, SDL_RW_SEEK_END
62 *
63 * \return the final offset in the data stream, or -1 on error.
64 */
65 Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
66 int whence);
67
68 /**
69 * Read up to \c size bytes from the data stream to the area pointed
70 * at by \c ptr.
71 *
72 * It is an error to use a negative \c size, but this parameter is
73 * signed so you definitely cannot overflow the return value on a
74 * successful run with enormous amounts of data.
75 *
76 * \return the number of objects read, or 0 on end of file, or -1 on error.
77 */
78 Sint64 (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
79 Sint64 size);
80
81 /**
82 * Write exactly \c size bytes from the area pointed at by \c ptr
83 * to data stream. May write less than requested (error, non-blocking i/o,
84 * etc). Returns -1 on error when nothing was written.
85 *
86 * It is an error to use a negative \c size, but this parameter is
87 * signed so you definitely cannot overflow the return value on a
88 * successful run with enormous amounts of data.
89 *
90 * \return the number of bytes written, which might be less than \c size,
91 * and -1 on error.
92 */
93 Sint64 (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
94 Sint64 size);
95
96 /**
97 * Close and free an allocated SDL_RWops structure.
98 *
99 * \return 0 if successful or -1 on write error when flushing data.
100 */
101 int (SDLCALL * close) (struct SDL_RWops * context);
102
104 union
105 {
106#if defined(__ANDROID__)
107 struct
108 {
109 void *asset;
110 } androidio;
111#elif defined(__WIN32__) || defined(__GDK__)
112 struct
113 {
114 SDL_bool append;
115 void *h;
116 struct
117 {
118 void *data;
119 size_t size;
120 size_t left;
121 } buffer;
122 } windowsio;
123#endif
124
125 struct
126 {
128 void *fp;
130
131 struct
132 {
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,
215 const char *mode);
216
217/**
218 * Use this function to prepare a read-write memory buffer for use with
219 * SDL_RWops.
220 *
221 * This function sets up an SDL_RWops struct based on a memory area of a
222 * certain size, for both read and write access.
223 *
224 * This memory buffer is not copied by the RWops; the pointer you provide must
225 * remain valid until you close the stream. Closing the stream will not free
226 * the original buffer.
227 *
228 * If you need to make sure the RWops never writes to the memory buffer, you
229 * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
230 *
231 * \param mem a pointer to a buffer to feed an SDL_RWops stream
232 * \param size the buffer size, in bytes
233 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
234 * SDL_GetError() for more information.
235 *
236 * \since This function is available since SDL 3.0.0.
237 *
238 * \sa SDL_RWclose
239 * \sa SDL_RWFromConstMem
240 * \sa SDL_RWFromFile
241 * \sa SDL_RWFromMem
242 * \sa SDL_RWread
243 * \sa SDL_RWseek
244 * \sa SDL_RWtell
245 * \sa SDL_RWwrite
246 */
247extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
248
249/**
250 * Use this function to prepare a read-only memory buffer for use with RWops.
251 *
252 * This function sets up an SDL_RWops struct based on a memory area of a
253 * certain size. It assumes the memory area is not writable.
254 *
255 * Attempting to write to this RWops stream will report an error without
256 * writing to the memory buffer.
257 *
258 * This memory buffer is not copied by the RWops; the pointer you provide must
259 * remain valid until you close the stream. Closing the stream will not free
260 * the original buffer.
261 *
262 * If you need to write to a memory buffer, you should use SDL_RWFromMem()
263 * with a writable buffer of memory instead.
264 *
265 * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream
266 * \param size the buffer size, in bytes
267 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
268 * SDL_GetError() for more information.
269 *
270 * \since This function is available since SDL 3.0.0.
271 *
272 * \sa SDL_RWclose
273 * \sa SDL_RWFromConstMem
274 * \sa SDL_RWFromFile
275 * \sa SDL_RWFromMem
276 * \sa SDL_RWread
277 * \sa SDL_RWseek
278 * \sa SDL_RWtell
279 */
280extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
281 int 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 a 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 a 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 area 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 * area);
335
336#define SDL_RW_SEEK_SET 0 /**< Seek from the beginning of data */
337#define SDL_RW_SEEK_CUR 1 /**< Seek relative to current read point */
338#define SDL_RW_SEEK_END 2 /**< Seek relative to the end of data */
339
340/**
341 * Use this function to get the size of the data stream in an SDL_RWops.
342 *
343 * Prior to SDL 2.0.10, this function was a macro.
344 *
345 * \param context the SDL_RWops to get the size of the data stream from
346 * \returns the size of the data stream in the SDL_RWops on success, -1 if
347 * unknown or a negative error code on failure; call SDL_GetError()
348 * for more information.
349 *
350 * \since This function is available since SDL 3.0.0.
351 */
352extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
353
354/**
355 * Seek within an SDL_RWops data stream.
356 *
357 * This function seeks to byte `offset`, relative to `whence`.
358 *
359 * `whence` may be any of the following values:
360 *
361 * - `SDL_RW_SEEK_SET`: seek from the beginning of data
362 * - `SDL_RW_SEEK_CUR`: seek relative to current read point
363 * - `SDL_RW_SEEK_END`: seek relative to the end of data
364 *
365 * If this stream can not seek, it will return -1.
366 *
367 * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
368 * `seek` method appropriately, to simplify application development.
369 *
370 * Prior to SDL 2.0.10, this function was a macro.
371 *
372 * \param context a pointer to an SDL_RWops structure
373 * \param offset an offset in bytes, relative to **whence** location; can be
374 * negative
375 * \param whence any of `SDL_RW_SEEK_SET`, `SDL_RW_SEEK_CUR`,
376 * `SDL_RW_SEEK_END`
377 * \returns the final offset in the data stream after the seek or -1 on error.
378 *
379 * \since This function is available since SDL 3.0.0.
380 *
381 * \sa SDL_RWclose
382 * \sa SDL_RWFromConstMem
383 * \sa SDL_RWFromFile
384 * \sa SDL_RWFromMem
385 * \sa SDL_RWread
386 * \sa SDL_RWtell
387 * \sa SDL_RWwrite
388 */
389extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context,
390 Sint64 offset, int whence);
391
392/**
393 * Determine the current read/write offset in an SDL_RWops data stream.
394 *
395 * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
396 * method, with an offset of 0 bytes from `SDL_RW_SEEK_CUR`, to simplify
397 * application development.
398 *
399 * Prior to SDL 2.0.10, this function was a macro.
400 *
401 * \param context a SDL_RWops data stream object from which to get the current
402 * offset
403 * \returns the current offset in the stream, or -1 if the information can not
404 * be determined.
405 *
406 * \since This function is available since SDL 3.0.0.
407 *
408 * \sa SDL_RWclose
409 * \sa SDL_RWFromConstMem
410 * \sa SDL_RWFromFile
411 * \sa SDL_RWFromMem
412 * \sa SDL_RWread
413 * \sa SDL_RWseek
414 * \sa SDL_RWwrite
415 */
416extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
417
418/**
419 * Read from a data source.
420 *
421 * This function reads up `size` bytes from the data source to the area
422 * pointed at by `ptr`. This function may read less bytes than requested. It
423 * will return zero when the data stream is completely read, or -1 on error.
424 * For streams that support non-blocking operation, if nothing was read
425 * because it would require blocking, this function returns -2 to distinguish
426 * that this is not an error or end-of-file, and the caller can try again
427 * later.
428 *
429 * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
430 * `read` method appropriately, to simplify application development.
431 *
432 * It is an error to specify a negative `size`, but this parameter is signed
433 * so you definitely cannot overflow the return value on a successful run with
434 * enormous amounts of data.
435 *
436 * \param context a pointer to an SDL_RWops structure
437 * \param ptr a pointer to a buffer to read data into
438 * \param size the number of bytes to read from the data source.
439 * \returns the number of bytes read, 0 at end of file, -1 on error, and -2
440 * for data not ready with a non-blocking context.
441 *
442 * \since This function is available since SDL 3.0.0.
443 *
444 * \sa SDL_RWclose
445 * \sa SDL_RWFromConstMem
446 * \sa SDL_RWFromFile
447 * \sa SDL_RWFromMem
448 * \sa SDL_RWseek
449 * \sa SDL_RWwrite
450 */
451extern DECLSPEC Sint64 SDLCALL SDL_RWread(SDL_RWops *context, void *ptr, Sint64 size);
452
453/**
454 * Write to an SDL_RWops data stream.
455 *
456 * This function writes exactly `size` bytes from the area pointed at by `ptr`
457 * to the stream. If this fails for any reason, it'll return less than `size`
458 * to demonstrate how far the write progressed. On success, it returns `num`.
459 *
460 * On error, this function still attempts to write as much as possible, so it
461 * might return a positive value less than the requested write size. If the
462 * function failed to write anything and there was an actual error, it will
463 * return -1. For streams that support non-blocking operation, if nothing was
464 * written because it would require blocking, this function returns -2 to
465 * distinguish that this is not an error and the caller can try again later.
466 *
467 * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
468 * `write` method appropriately, to simplify application development.
469 *
470 * It is an error to specify a negative `size`, but this parameter is signed
471 * so you definitely cannot overflow the return value on a successful run with
472 * enormous amounts of data.
473 *
474 * \param context a pointer to an SDL_RWops structure
475 * \param ptr a pointer to a buffer containing data to write
476 * \param size the number of bytes to write
477 * \returns the number of bytes written, which will be less than `num` on
478 * error; call SDL_GetError() for more information.
479 *
480 * \since This function is available since SDL 3.0.0.
481 *
482 * \sa SDL_RWclose
483 * \sa SDL_RWFromConstMem
484 * \sa SDL_RWFromFile
485 * \sa SDL_RWFromMem
486 * \sa SDL_RWread
487 * \sa SDL_RWseek
488 */
489extern DECLSPEC Sint64 SDLCALL SDL_RWwrite(SDL_RWops *context,
490 const void *ptr, Sint64 size);
491
492/**
493 * Close and free an allocated SDL_RWops structure.
494 *
495 * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
496 * resources used by the stream and frees the SDL_RWops itself with
497 * SDL_DestroyRW(). This returns 0 on success, or -1 if the stream failed to
498 * flush to its output (e.g. to disk).
499 *
500 * Note that if this fails to flush the stream to disk, this function reports
501 * an error, but the SDL_RWops is still invalid once this function returns.
502 *
503 * Prior to SDL 2.0.10, this function was a macro.
504 *
505 * \param context SDL_RWops structure to close
506 * \returns 0 on success or a negative error code on failure; call
507 * SDL_GetError() for more information.
508 *
509 * \since This function is available since SDL 3.0.0.
510 *
511 * \sa SDL_RWFromConstMem
512 * \sa SDL_RWFromFile
513 * \sa SDL_RWFromMem
514 * \sa SDL_RWread
515 * \sa SDL_RWseek
516 * \sa SDL_RWwrite
517 */
518extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
519
520/**
521 * Load all the data from an SDL data stream.
522 *
523 * The data is allocated with a zero byte at the end (null terminated) for
524 * convenience. This extra byte is not included in the value reported via
525 * `datasize`.
526 *
527 * The data should be freed with SDL_free().
528 *
529 * \param src the SDL_RWops to read all available data from
530 * \param datasize if not NULL, will store the number of bytes read
531 * \param freesrc if non-zero, calls SDL_RWclose() on `src` before returning
532 * \returns the data, or NULL if there was an error.
533 *
534 * \since This function is available since SDL 3.0.0.
535 */
536extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
537 size_t *datasize,
538 int freesrc);
539
540/**
541 * Load all the data from a file path.
542 *
543 * The data is allocated with a zero byte at the end (null terminated) for
544 * convenience. This extra byte is not included in the value reported via
545 * `datasize`.
546 *
547 * The data should be freed with SDL_free().
548 *
549 * Prior to SDL 2.0.10, this function was a macro wrapping around
550 * SDL_LoadFile_RW.
551 *
552 * \param file the path to read all available data from
553 * \param datasize if not NULL, will store the number of bytes read
554 * \returns the data, or NULL if there was an error.
555 *
556 * \since This function is available since SDL 3.0.0.
557 */
558extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
559
560/**
561 * \name Read endian functions
562 *
563 * Read an item of the specified endianness and return in native format.
564 */
565/* @{ */
566
567/**
568 * Use this function to read a byte from an SDL_RWops.
569 *
570 * \param src the SDL_RWops to read from
571 * \returns the read byte on success or 0 on failure; call SDL_GetError() for
572 * more information.
573 *
574 * \since This function is available since SDL 3.0.0.
575 *
576 * \sa SDL_WriteU8
577 */
578extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
579
580/**
581 * Use this function to read 16 bits of little-endian data from an SDL_RWops
582 * and return in native format.
583 *
584 * SDL byteswaps the data only if necessary, so the data returned will be in
585 * the native byte order.
586 *
587 * \param src the stream from which to read data
588 * \returns 16 bits of data in the native byte order of the platform.
589 *
590 * \since This function is available since SDL 3.0.0.
591 *
592 * \sa SDL_ReadBE16
593 */
594extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
595
596/**
597 * Use this function to read 16 bits of big-endian data from an SDL_RWops and
598 * return in native format.
599 *
600 * SDL byteswaps the data only if necessary, so the data returned will be in
601 * the native byte order.
602 *
603 * \param src the stream from which to read data
604 * \returns 16 bits of data in the native byte order of the platform.
605 *
606 * \since This function is available since SDL 3.0.0.
607 *
608 * \sa SDL_ReadLE16
609 */
610extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
611
612/**
613 * Use this function to read 32 bits of little-endian data from an SDL_RWops
614 * and return in native format.
615 *
616 * SDL byteswaps the data only if necessary, so the data returned will be in
617 * the native byte order.
618 *
619 * \param src the stream from which to read data
620 * \returns 32 bits of data in the native byte order of the platform.
621 *
622 * \since This function is available since SDL 3.0.0.
623 *
624 * \sa SDL_ReadBE32
625 */
626extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
627
628/**
629 * Use this function to read 32 bits of big-endian data from an SDL_RWops and
630 * return in native format.
631 *
632 * SDL byteswaps the data only if necessary, so the data returned will be in
633 * the native byte order.
634 *
635 * \param src the stream from which to read data
636 * \returns 32 bits of data in the native byte order of the platform.
637 *
638 * \since This function is available since SDL 3.0.0.
639 *
640 * \sa SDL_ReadLE32
641 */
642extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
643
644/**
645 * Use this function to read 64 bits of little-endian data from an SDL_RWops
646 * and return in native format.
647 *
648 * SDL byteswaps the data only if necessary, so the data returned will be in
649 * the native byte order.
650 *
651 * \param src the stream from which to read data
652 * \returns 64 bits of data in the native byte order of the platform.
653 *
654 * \since This function is available since SDL 3.0.0.
655 *
656 * \sa SDL_ReadBE64
657 */
658extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
659
660/**
661 * Use this function to read 64 bits of big-endian data from an SDL_RWops and
662 * return in native format.
663 *
664 * SDL byteswaps the data only if necessary, so the data returned will be in
665 * the native byte order.
666 *
667 * \param src the stream from which to read data
668 * \returns 64 bits of data in the native byte order of the platform.
669 *
670 * \since This function is available since SDL 3.0.0.
671 *
672 * \sa SDL_ReadLE64
673 */
674extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
675/* @} *//* Read endian functions */
676
677/**
678 * \name Write endian functions
679 *
680 * Write an item of native format to the specified endianness.
681 */
682/* @{ */
683
684/**
685 * Use this function to write a byte to an SDL_RWops.
686 *
687 * \param dst the SDL_RWops to write to
688 * \param value the byte value to write
689 * \returns 1 on success or 0 on failure; call SDL_GetError() for more
690 * information.
691 *
692 * \since This function is available since SDL 3.0.0.
693 *
694 * \sa SDL_ReadU8
695 */
696extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
697
698/**
699 * Use this function to write 16 bits in native format to a SDL_RWops as
700 * little-endian data.
701 *
702 * SDL byteswaps the data only if necessary, so the application always
703 * specifies native format, and the data written will be in little-endian
704 * format.
705 *
706 * \param dst the stream to which data will be written
707 * \param value the data to be written, in native format
708 * \returns 1 on successful write, 0 on error.
709 *
710 * \since This function is available since SDL 3.0.0.
711 *
712 * \sa SDL_WriteBE16
713 */
714extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
715
716/**
717 * Use this function to write 16 bits in native format to a SDL_RWops as
718 * big-endian data.
719 *
720 * SDL byteswaps the data only if necessary, so the application always
721 * specifies native format, and the data written will be in big-endian format.
722 *
723 * \param dst the stream to which data will be written
724 * \param value the data to be written, in native format
725 * \returns 1 on successful write, 0 on error.
726 *
727 * \since This function is available since SDL 3.0.0.
728 *
729 * \sa SDL_WriteLE16
730 */
731extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
732
733/**
734 * Use this function to write 32 bits in native format to a SDL_RWops as
735 * little-endian data.
736 *
737 * SDL byteswaps the data only if necessary, so the application always
738 * specifies native format, and the data written will be in little-endian
739 * format.
740 *
741 * \param dst the stream to which data will be written
742 * \param value the data to be written, in native format
743 * \returns 1 on successful write, 0 on error.
744 *
745 * \since This function is available since SDL 3.0.0.
746 *
747 * \sa SDL_WriteBE32
748 */
749extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
750
751/**
752 * Use this function to write 32 bits in native format to a SDL_RWops as
753 * big-endian data.
754 *
755 * SDL byteswaps the data only if necessary, so the application always
756 * specifies native format, and the data written will be in big-endian format.
757 *
758 * \param dst the stream to which data will be written
759 * \param value the data to be written, in native format
760 * \returns 1 on successful write, 0 on error.
761 *
762 * \since This function is available since SDL 3.0.0.
763 *
764 * \sa SDL_WriteLE32
765 */
766extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
767
768/**
769 * Use this function to write 64 bits in native format to a SDL_RWops as
770 * little-endian data.
771 *
772 * SDL byteswaps the data only if necessary, so the application always
773 * specifies native format, and the data written will be in little-endian
774 * format.
775 *
776 * \param dst the stream to which data will be written
777 * \param value the data to be written, in native format
778 * \returns 1 on successful write, 0 on error.
779 *
780 * \since This function is available since SDL 3.0.0.
781 *
782 * \sa SDL_WriteBE64
783 */
784extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
785
786/**
787 * Use this function to write 64 bits in native format to a SDL_RWops as
788 * big-endian data.
789 *
790 * SDL byteswaps the data only if necessary, so the application always
791 * specifies native format, and the data written will be in big-endian format.
792 *
793 * \param dst the stream to which data will be written
794 * \param value the data to be written, in native format
795 * \returns 1 on successful write, 0 on error.
796 *
797 * \since This function is available since SDL 3.0.0.
798 *
799 * \sa SDL_WriteLE64
800 */
801extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
802/* @} *//* Write endian functions */
803
804/* Ends C function definitions when using C++ */
805#ifdef __cplusplus
806}
807#endif
808#include <SDL3/SDL_close_code.h>
809
810#endif /* SDL_rwops_h_ */
size_t SDL_WriteBE64(SDL_RWops *dst, Uint64 value)
Uint16 SDL_ReadLE16(SDL_RWops *src)
void SDL_DestroyRW(SDL_RWops *area)
Uint32 SDL_ReadLE32(SDL_RWops *src)
Sint64 SDL_RWsize(SDL_RWops *context)
size_t SDL_WriteLE32(SDL_RWops *dst, Uint32 value)
size_t SDL_WriteLE16(SDL_RWops *dst, Uint16 value)
Uint16 SDL_ReadBE16(SDL_RWops *src)
SDL_RWops * SDL_RWFromFile(const char *file, const char *mode)
size_t SDL_WriteBE16(SDL_RWops *dst, Uint16 value)
size_t SDL_WriteBE32(SDL_RWops *dst, Uint32 value)
Sint64 SDL_RWseek(SDL_RWops *context, Sint64 offset, int whence)
Sint64 SDL_RWwrite(SDL_RWops *context, const void *ptr, Sint64 size)
SDL_RWops * SDL_RWFromMem(void *mem, int size)
Sint64 SDL_RWtell(SDL_RWops *context)
Sint64 SDL_RWread(SDL_RWops *context, void *ptr, Sint64 size)
void * SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, int freesrc)
Uint64 SDL_ReadLE64(SDL_RWops *src)
Uint64 SDL_ReadBE64(SDL_RWops *src)
size_t SDL_WriteU8(SDL_RWops *dst, Uint8 value)
Uint32 SDL_ReadBE32(SDL_RWops *src)
SDL_RWops * SDL_CreateRW(void)
int SDL_RWclose(SDL_RWops *context)
Uint8 SDL_ReadU8(SDL_RWops *src)
SDL_RWops * SDL_RWFromConstMem(const void *mem, int size)
size_t SDL_WriteLE64(SDL_RWops *dst, Uint64 value)
void * SDL_LoadFile(const char *file, size_t *datasize)
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
SDL_MALLOC size_t size
Definition: SDL_stdinc.h:385
SDL_bool
Definition: SDL_stdinc.h:130
uint64_t Uint64
Definition: SDL_stdinc.h:184
uint32_t Uint32
Definition: SDL_stdinc.h:171
struct SDL_RWops::@2::@5 unknown
Uint32 type
Definition: SDL_rwops.h:103
SDL_bool autoclose
Definition: SDL_rwops.h:127
Uint8 * stop
Definition: SDL_rwops.h:135
Uint8 * here
Definition: SDL_rwops.h:134
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:101
struct SDL_RWops::@2::@4 mem
Sint64(* read)(struct SDL_RWops *context, void *ptr, Sint64 size)
Definition: SDL_rwops.h:78
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
void * fp
Definition: SDL_rwops.h:128
void * data1
Definition: SDL_rwops.h:139
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
union SDL_RWops::@2 hidden
void * data2
Definition: SDL_rwops.h:140
Sint64(* write)(struct SDL_RWops *context, const void *ptr, Sint64 size)
Definition: SDL_rwops.h:93
struct SDL_RWops::@2::@3 stdio
Uint8 * base
Definition: SDL_rwops.h:133