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#ifdef __ANDROID__
107 struct
108 {
109 void *asset;
110 } androidio;
111
112#elif defined(__WIN32__) || defined(__GDK__)
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,
217 const char *mode);
218
219/**
220 * Use this function to prepare a read-write memory buffer for use with
221 * SDL_RWops.
222 *
223 * This function sets up an SDL_RWops struct based on a memory area of a
224 * certain size, for both read and write access.
225 *
226 * This memory buffer is not copied by the RWops; the pointer you provide must
227 * remain valid until you close the stream. Closing the stream will not free
228 * the original buffer.
229 *
230 * If you need to make sure the RWops never writes to the memory buffer, you
231 * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
232 *
233 * \param mem a pointer to a buffer to feed an SDL_RWops stream
234 * \param size the buffer size, in bytes
235 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
236 * SDL_GetError() for more information.
237 *
238 * \since This function is available since SDL 3.0.0.
239 *
240 * \sa SDL_RWclose
241 * \sa SDL_RWFromConstMem
242 * \sa SDL_RWFromFile
243 * \sa SDL_RWFromMem
244 * \sa SDL_RWread
245 * \sa SDL_RWseek
246 * \sa SDL_RWtell
247 * \sa SDL_RWwrite
248 */
249extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, size_t size);
250
251/**
252 * Use this function to prepare a read-only memory buffer for use with RWops.
253 *
254 * This function sets up an SDL_RWops struct based on a memory area of a
255 * certain size. It assumes the memory area is not writable.
256 *
257 * Attempting to write to this RWops stream will report an error without
258 * writing to the memory buffer.
259 *
260 * This memory buffer is not copied by the RWops; the pointer you provide must
261 * remain valid until you close the stream. Closing the stream will not free
262 * the original buffer.
263 *
264 * If you need to write to a memory buffer, you should use SDL_RWFromMem()
265 * with a writable buffer of memory instead.
266 *
267 * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream
268 * \param size the buffer size, in bytes
269 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
270 * SDL_GetError() for more information.
271 *
272 * \since This function is available since SDL 3.0.0.
273 *
274 * \sa SDL_RWclose
275 * \sa SDL_RWFromConstMem
276 * \sa SDL_RWFromFile
277 * \sa SDL_RWFromMem
278 * \sa SDL_RWread
279 * \sa SDL_RWseek
280 * \sa SDL_RWtell
281 */
282extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
283 size_t size);
284
285/* @} *//* RWFrom functions */
286
287
288/**
289 * Use this function to allocate an empty, unpopulated SDL_RWops structure.
290 *
291 * Applications do not need to use this function unless they are providing
292 * their own SDL_RWops implementation. If you just need a SDL_RWops to
293 * read/write a common data source, you should use the built-in
294 * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc.
295 *
296 * You must free the returned pointer with SDL_DestroyRW(). Depending on your
297 * operating system and compiler, there may be a difference between the
298 * malloc() and free() your program uses and the versions SDL calls
299 * internally. Trying to mix the two can cause crashing such as segmentation
300 * faults. Since all SDL_RWops must free themselves when their **close**
301 * method is called, all SDL_RWops must be allocated through this function, so
302 * they can all be freed correctly with SDL_DestroyRW().
303 *
304 * \returns a pointer to the allocated memory on success, or NULL on failure;
305 * call SDL_GetError() for more information.
306 *
307 * \since This function is available since SDL 3.0.0.
308 *
309 * \sa SDL_DestroyRW
310 */
311extern DECLSPEC SDL_RWops *SDLCALL SDL_CreateRW(void);
312
313/**
314 * Use this function to free an SDL_RWops structure allocated by
315 * SDL_CreateRW().
316 *
317 * Applications do not need to use this function unless they are providing
318 * their own SDL_RWops implementation. If you just need a SDL_RWops to
319 * read/write a common data source, you should use the built-in
320 * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and
321 * call the **close** method on those SDL_RWops pointers when you are done
322 * with them.
323 *
324 * Only use SDL_DestroyRW() on pointers returned by SDL_CreateRW(). The
325 * pointer is invalid as soon as this function returns. Any extra memory
326 * allocated during creation of the SDL_RWops is not freed by SDL_DestroyRW();
327 * the programmer must be responsible for managing that memory in their
328 * **close** method.
329 *
330 * \param area the SDL_RWops structure to be freed
331 *
332 * \since This function is available since SDL 3.0.0.
333 *
334 * \sa SDL_CreateRW
335 */
336extern DECLSPEC void SDLCALL SDL_DestroyRW(SDL_RWops * area);
337
338#define SDL_RW_SEEK_SET 0 /**< Seek from the beginning of data */
339#define SDL_RW_SEEK_CUR 1 /**< Seek relative to current read point */
340#define SDL_RW_SEEK_END 2 /**< Seek relative to the end of data */
341
342/**
343 * Use this function to get the size of the data stream in an SDL_RWops.
344 *
345 * Prior to SDL 2.0.10, this function was a macro.
346 *
347 * \param context the SDL_RWops to get the size of the data stream from
348 * \returns the size of the data stream in the SDL_RWops on success, -1 if
349 * unknown or a negative error code on failure; call SDL_GetError()
350 * for more information.
351 *
352 * \since This function is available since SDL 3.0.0.
353 */
354extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
355
356/**
357 * Seek within an SDL_RWops data stream.
358 *
359 * This function seeks to byte `offset`, relative to `whence`.
360 *
361 * `whence` may be any of the following values:
362 *
363 * - `SDL_RW_SEEK_SET`: seek from the beginning of data
364 * - `SDL_RW_SEEK_CUR`: seek relative to current read point
365 * - `SDL_RW_SEEK_END`: seek relative to the end of data
366 *
367 * If this stream can not seek, it will return -1.
368 *
369 * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
370 * `seek` method appropriately, to simplify application development.
371 *
372 * Prior to SDL 2.0.10, this function was a macro.
373 *
374 * \param context a pointer to an SDL_RWops structure
375 * \param offset an offset in bytes, relative to **whence** location; can be
376 * negative
377 * \param whence any of `SDL_RW_SEEK_SET`, `SDL_RW_SEEK_CUR`,
378 * `SDL_RW_SEEK_END`
379 * \returns the final offset in the data stream after the seek or -1 on error.
380 *
381 * \since This function is available since SDL 3.0.0.
382 *
383 * \sa SDL_RWclose
384 * \sa SDL_RWFromConstMem
385 * \sa SDL_RWFromFile
386 * \sa SDL_RWFromMem
387 * \sa SDL_RWread
388 * \sa SDL_RWtell
389 * \sa SDL_RWwrite
390 */
391extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context,
392 Sint64 offset, int whence);
393
394/**
395 * Determine the current read/write offset in an SDL_RWops data stream.
396 *
397 * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
398 * method, with an offset of 0 bytes from `SDL_RW_SEEK_CUR`, to simplify
399 * application development.
400 *
401 * Prior to SDL 2.0.10, this function was a macro.
402 *
403 * \param context a SDL_RWops data stream object from which to get the current
404 * offset
405 * \returns the current offset in the stream, or -1 if the information can not
406 * be determined.
407 *
408 * \since This function is available since SDL 3.0.0.
409 *
410 * \sa SDL_RWclose
411 * \sa SDL_RWFromConstMem
412 * \sa SDL_RWFromFile
413 * \sa SDL_RWFromMem
414 * \sa SDL_RWread
415 * \sa SDL_RWseek
416 * \sa SDL_RWwrite
417 */
418extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
419
420/**
421 * Read from a data source.
422 *
423 * This function reads up `size` bytes from the data source to the area
424 * pointed at by `ptr`. This function may read less bytes than requested. It
425 * will return zero when the data stream is completely read, or -1 on error.
426 * For streams that support non-blocking operation, if nothing was read
427 * because it would require blocking, this function returns -2 to distinguish
428 * that this is not an error or end-of-file, and the caller can try again
429 * later.
430 *
431 * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
432 * `read` method appropriately, to simplify application development.
433 *
434 * It is an error to specify a negative `size`, but this parameter is signed
435 * so you definitely cannot overflow the return value on a successful run with
436 * enormous amounts of data.
437 *
438 * \param context a pointer to an SDL_RWops structure
439 * \param ptr a pointer to a buffer to read data into
440 * \param size the number of bytes to read from the data source.
441 * \returns the number of bytes read, 0 at end of file, -1 on error, and -2
442 * for data not ready with a non-blocking context.
443 *
444 * \since This function is available since SDL 3.0.0.
445 *
446 * \sa SDL_RWclose
447 * \sa SDL_RWFromConstMem
448 * \sa SDL_RWFromFile
449 * \sa SDL_RWFromMem
450 * \sa SDL_RWseek
451 * \sa SDL_RWwrite
452 */
453extern DECLSPEC Sint64 SDLCALL SDL_RWread(SDL_RWops *context, void *ptr, Sint64 size);
454
455/**
456 * Write to an SDL_RWops data stream.
457 *
458 * This function writes exactly `size` bytes from the area pointed at by `ptr`
459 * to the stream. If this fails for any reason, it'll return less than `size`
460 * to demonstrate how far the write progressed. On success, it returns `num`.
461 *
462 * On error, this function still attempts to write as much as possible, so it
463 * might return a positive value less than the requested write size. If the
464 * function failed to write anything and there was an actual error, it will
465 * return -1. For streams that support non-blocking operation, if nothing was
466 * written because it would require blocking, this function returns -2 to
467 * distinguish that this is not an error and the caller can try again later.
468 *
469 * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
470 * `write` method appropriately, to simplify application development.
471 *
472 * It is an error to specify a negative `size`, but this parameter is signed
473 * so you definitely cannot overflow the return value on a successful run with
474 * enormous amounts of data.
475 *
476 * \param context a pointer to an SDL_RWops structure
477 * \param ptr a pointer to a buffer containing data to write
478 * \param size the number of bytes to write
479 * \returns the number of bytes written, which will be less than `num` on
480 * error; call SDL_GetError() for more information.
481 *
482 * \since This function is available since SDL 3.0.0.
483 *
484 * \sa SDL_RWclose
485 * \sa SDL_RWFromConstMem
486 * \sa SDL_RWFromFile
487 * \sa SDL_RWFromMem
488 * \sa SDL_RWread
489 * \sa SDL_RWseek
490 */
491extern DECLSPEC Sint64 SDLCALL SDL_RWwrite(SDL_RWops *context,
492 const void *ptr, Sint64 size);
493
494/**
495 * Close and free an allocated SDL_RWops structure.
496 *
497 * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
498 * resources used by the stream and frees the SDL_RWops itself with
499 * SDL_DestroyRW(). This returns 0 on success, or -1 if the stream failed to
500 * flush to its output (e.g. to disk).
501 *
502 * Note that if this fails to flush the stream to disk, this function reports
503 * an error, but the SDL_RWops is still invalid once this function returns.
504 *
505 * Prior to SDL 2.0.10, this function was a macro.
506 *
507 * \param context SDL_RWops structure to close
508 * \returns 0 on success or a negative error code on failure; call
509 * SDL_GetError() for more information.
510 *
511 * \since This function is available since SDL 3.0.0.
512 *
513 * \sa SDL_RWFromConstMem
514 * \sa SDL_RWFromFile
515 * \sa SDL_RWFromMem
516 * \sa SDL_RWread
517 * \sa SDL_RWseek
518 * \sa SDL_RWwrite
519 */
520extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
521
522/**
523 * Load all the data from an SDL data stream.
524 *
525 * The data is allocated with a zero byte at the end (null terminated) for
526 * convenience. This extra byte is not included in the value reported via
527 * `datasize`.
528 *
529 * The data should be freed with SDL_free().
530 *
531 * \param src the SDL_RWops to read all available data from
532 * \param datasize if not NULL, will store the number of bytes read
533 * \param freesrc if SDL_TRUE, calls SDL_RWclose() on `src` before returning,
534 * even in the case of an error
535 * \returns the data, or NULL if there was an error.
536 *
537 * \since This function is available since SDL 3.0.0.
538 */
539extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
540 size_t *datasize,
541 SDL_bool freesrc);
542
543/**
544 * Load all the data from a file path.
545 *
546 * The data is allocated with a zero byte at the end (null terminated) for
547 * convenience. This extra byte is not included in the value reported via
548 * `datasize`.
549 *
550 * The data should be freed with SDL_free().
551 *
552 * Prior to SDL 2.0.10, this function was a macro wrapping around
553 * SDL_LoadFile_RW.
554 *
555 * \param file the path to read all available data from
556 * \param datasize if not NULL, will store the number of bytes read
557 * \returns the data, or NULL if there was an error.
558 *
559 * \since This function is available since SDL 3.0.0.
560 */
561extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
562
563/**
564 * \name Read endian functions
565 *
566 * Read an item of the specified endianness and return in native format.
567 */
568/* @{ */
569
570/**
571 * Use this function to read a byte from an SDL_RWops.
572 *
573 * \param src the SDL_RWops to read from
574 * \returns the read byte on success or 0 on failure; call SDL_GetError() for
575 * more information.
576 *
577 * \since This function is available since SDL 3.0.0.
578 *
579 * \sa SDL_WriteU8
580 */
581extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
582
583/**
584 * Use this function to read 16 bits of little-endian data from an SDL_RWops
585 * and return in native format.
586 *
587 * SDL byteswaps the data only if necessary, so the data returned will be in
588 * the native byte order.
589 *
590 * \param src the stream from which to read data
591 * \returns 16 bits of data in the native byte order of the platform.
592 *
593 * \since This function is available since SDL 3.0.0.
594 *
595 * \sa SDL_ReadBE16
596 */
597extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
598
599/**
600 * Use this function to read 16 bits of big-endian data from an SDL_RWops and
601 * return in native format.
602 *
603 * SDL byteswaps the data only if necessary, so the data returned will be in
604 * the native byte order.
605 *
606 * \param src the stream from which to read data
607 * \returns 16 bits of data in the native byte order of the platform.
608 *
609 * \since This function is available since SDL 3.0.0.
610 *
611 * \sa SDL_ReadLE16
612 */
613extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
614
615/**
616 * Use this function to read 32 bits of little-endian data from an SDL_RWops
617 * and return in native format.
618 *
619 * SDL byteswaps the data only if necessary, so the data returned will be in
620 * the native byte order.
621 *
622 * \param src the stream from which to read data
623 * \returns 32 bits of data in the native byte order of the platform.
624 *
625 * \since This function is available since SDL 3.0.0.
626 *
627 * \sa SDL_ReadBE32
628 */
629extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
630
631/**
632 * Use this function to read 32 bits of big-endian data from an SDL_RWops and
633 * return in native format.
634 *
635 * SDL byteswaps the data only if necessary, so the data returned will be in
636 * the native byte order.
637 *
638 * \param src the stream from which to read data
639 * \returns 32 bits of data in the native byte order of the platform.
640 *
641 * \since This function is available since SDL 3.0.0.
642 *
643 * \sa SDL_ReadLE32
644 */
645extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
646
647/**
648 * Use this function to read 64 bits of little-endian data from an SDL_RWops
649 * and return in native format.
650 *
651 * SDL byteswaps the data only if necessary, so the data returned will be in
652 * the native byte order.
653 *
654 * \param src the stream from which to read data
655 * \returns 64 bits of data in the native byte order of the platform.
656 *
657 * \since This function is available since SDL 3.0.0.
658 *
659 * \sa SDL_ReadBE64
660 */
661extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
662
663/**
664 * Use this function to read 64 bits of big-endian data from an SDL_RWops and
665 * return in native format.
666 *
667 * SDL byteswaps the data only if necessary, so the data returned will be in
668 * the native byte order.
669 *
670 * \param src the stream from which to read data
671 * \returns 64 bits of data in the native byte order of the platform.
672 *
673 * \since This function is available since SDL 3.0.0.
674 *
675 * \sa SDL_ReadLE64
676 */
677extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
678/* @} *//* Read endian functions */
679
680/**
681 * \name Write endian functions
682 *
683 * Write an item of native format to the specified endianness.
684 */
685/* @{ */
686
687/**
688 * Use this function to write a byte to an SDL_RWops.
689 *
690 * \param dst the SDL_RWops to write to
691 * \param value the byte value to write
692 * \returns 1 on success or 0 on failure; call SDL_GetError() for more
693 * information.
694 *
695 * \since This function is available since SDL 3.0.0.
696 *
697 * \sa SDL_ReadU8
698 */
699extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
700
701/**
702 * Use this function to write 16 bits in native format to a SDL_RWops as
703 * little-endian data.
704 *
705 * SDL byteswaps the data only if necessary, so the application always
706 * specifies native format, and the data written will be in little-endian
707 * format.
708 *
709 * \param dst the stream to which data will be written
710 * \param value the data to be written, in native format
711 * \returns 1 on successful write, 0 on error.
712 *
713 * \since This function is available since SDL 3.0.0.
714 *
715 * \sa SDL_WriteBE16
716 */
717extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
718
719/**
720 * Use this function to write 16 bits in native format to a SDL_RWops as
721 * big-endian data.
722 *
723 * SDL byteswaps the data only if necessary, so the application always
724 * specifies native format, and the data written will be in big-endian format.
725 *
726 * \param dst the stream to which data will be written
727 * \param value the data to be written, in native format
728 * \returns 1 on successful write, 0 on error.
729 *
730 * \since This function is available since SDL 3.0.0.
731 *
732 * \sa SDL_WriteLE16
733 */
734extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
735
736/**
737 * Use this function to write 32 bits in native format to a SDL_RWops as
738 * little-endian data.
739 *
740 * SDL byteswaps the data only if necessary, so the application always
741 * specifies native format, and the data written will be in little-endian
742 * format.
743 *
744 * \param dst the stream to which data will be written
745 * \param value the data to be written, in native format
746 * \returns 1 on successful write, 0 on error.
747 *
748 * \since This function is available since SDL 3.0.0.
749 *
750 * \sa SDL_WriteBE32
751 */
752extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
753
754/**
755 * Use this function to write 32 bits in native format to a SDL_RWops as
756 * big-endian data.
757 *
758 * SDL byteswaps the data only if necessary, so the application always
759 * specifies native format, and the data written will be in big-endian format.
760 *
761 * \param dst the stream to which data will be written
762 * \param value the data to be written, in native format
763 * \returns 1 on successful write, 0 on error.
764 *
765 * \since This function is available since SDL 3.0.0.
766 *
767 * \sa SDL_WriteLE32
768 */
769extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
770
771/**
772 * Use this function to write 64 bits in native format to a SDL_RWops as
773 * little-endian data.
774 *
775 * SDL byteswaps the data only if necessary, so the application always
776 * specifies native format, and the data written will be in little-endian
777 * format.
778 *
779 * \param dst the stream to which data will be written
780 * \param value the data to be written, in native format
781 * \returns 1 on successful write, 0 on error.
782 *
783 * \since This function is available since SDL 3.0.0.
784 *
785 * \sa SDL_WriteBE64
786 */
787extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
788
789/**
790 * Use this function to write 64 bits in native format to a SDL_RWops as
791 * big-endian data.
792 *
793 * SDL byteswaps the data only if necessary, so the application always
794 * specifies native format, and the data written will be in big-endian format.
795 *
796 * \param dst the stream to which data will be written
797 * \param value the data to be written, in native format
798 * \returns 1 on successful write, 0 on error.
799 *
800 * \since This function is available since SDL 3.0.0.
801 *
802 * \sa SDL_WriteLE64
803 */
804extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
805/* @} *//* Write endian functions */
806
807/* Ends C function definitions when using C++ */
808#ifdef __cplusplus
809}
810#endif
811#include <SDL3/SDL_close_code.h>
812
813#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)
SDL_RWops * SDL_RWFromMem(void *mem, size_t size)
size_t SDL_WriteLE32(SDL_RWops *dst, Uint32 value)
size_t SDL_WriteLE16(SDL_RWops *dst, Uint16 value)
void * SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
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)
Sint64 SDL_RWtell(SDL_RWops *context)
Sint64 SDL_RWread(SDL_RWops *context, void *ptr, Sint64 size)
Uint64 SDL_ReadLE64(SDL_RWops *src)
SDL_RWops * SDL_RWFromConstMem(const void *mem, size_t size)
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)
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:391
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::@0::@3 unknown
Uint32 type
Definition: SDL_rwops.h:103
union SDL_RWops::@0 hidden
SDL_bool autoclose
Definition: SDL_rwops.h:128
struct SDL_RWops::@0::@1 stdio
Uint8 * stop
Definition: SDL_rwops.h:136
Uint8 * here
Definition: SDL_rwops.h:135
int(* close)(struct SDL_RWops *context)
Definition: SDL_rwops.h:101
Sint64(* read)(struct SDL_RWops *context, void *ptr, Sint64 size)
Definition: SDL_rwops.h:78
struct SDL_RWops::@0::@2 mem
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition: SDL_rwops.h:65
void * fp
Definition: SDL_rwops.h:129
void * data1
Definition: SDL_rwops.h:141
Sint64(* size)(struct SDL_RWops *context)
Definition: SDL_rwops.h:57
void * data2
Definition: SDL_rwops.h:142
Sint64(* write)(struct SDL_RWops *context, const void *ptr, Sint64 size)
Definition: SDL_rwops.h:93
Uint8 * base
Definition: SDL_rwops.h:134