SDL 2.0
SDL_rwops.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/* WIKI CATEGORY: RWOPS */
23
24/**
25 * # CategoryRWOPS
26 *
27 * This file provides a general interface for SDL to read and write data
28 * streams. It can easily be extended to files, memory, etc.
29 */
30
31#ifndef SDL_rwops_h_
32#define SDL_rwops_h_
33
34#include "SDL_stdinc.h"
35#include "SDL_error.h"
36
37#include "begin_code.h"
38/* Set up for C function definitions, even when using C++ */
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* RWops Types */
44#define SDL_RWOPS_UNKNOWN 0U /**< Unknown stream type */
45#define SDL_RWOPS_WINFILE 1U /**< Win32 file */
46#define SDL_RWOPS_STDFILE 2U /**< Stdio file */
47#define SDL_RWOPS_JNIFILE 3U /**< Android asset */
48#define SDL_RWOPS_MEMORY 4U /**< Memory stream */
49#define SDL_RWOPS_MEMORY_RO 5U /**< Read-Only memory stream */
50
51/**
52 * This is the read/write operation structure -- very basic.
53 */
54typedef struct SDL_RWops
55{
56 /**
57 * Return the size of the file in this rwops, or -1 if unknown
58 */
59 Sint64 (SDLCALL * size) (struct SDL_RWops * context);
60
61 /**
62 * Seek to `offset` relative to `whence`, one of stdio's whence values:
63 * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
64 *
65 * \return the final offset in the data stream, or -1 on error.
66 */
67 Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
68 int whence);
69
70 /**
71 * Read up to `maxnum` objects each of size `size` from the data
72 * stream to the area pointed at by `ptr`.
73 *
74 * \return the number of objects read, or 0 at error or end of file.
75 */
76 size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
77 size_t size, size_t maxnum);
78
79 /**
80 * Write exactly `num` objects each of size `size` from the area
81 * pointed at by `ptr` to data stream.
82 *
83 * \return the number of objects written, or 0 at error or end of file.
84 */
85 size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
86 size_t size, size_t num);
87
88 /**
89 * Close and free an allocated SDL_RWops structure.
90 *
91 * \return 0 if successful or -1 on write error when flushing data.
92 */
93 int (SDLCALL * close) (struct SDL_RWops * context);
94
96 union
97 {
98#if defined(__ANDROID__)
99 struct
100 {
101 void *asset;
102 } androidio;
103#elif defined(__WIN32__) || defined(__GDK__)
104 struct
105 {
107 void *h;
108 struct
109 {
110 void *data;
111 size_t size;
112 size_t left;
115#endif
116
117#ifdef HAVE_STDIO_H
118 struct
119 {
121 FILE *fp;
123#endif
124 struct
125 {
130 struct
131 {
132 void *data1;
133 void *data2;
136
137} SDL_RWops;
138
139
140/**
141 * \name RWFrom functions
142 *
143 * Functions to create SDL_RWops structures from various data streams.
144 */
145/* @{ */
146
147/**
148 * Use this function to create a new SDL_RWops structure for reading from
149 * and/or writing to a named file.
150 *
151 * The `mode` string is treated roughly the same as in a call to the C
152 * library's fopen(), even if SDL doesn't happen to use fopen() behind the
153 * scenes.
154 *
155 * Available `mode` strings:
156 *
157 * - "r": Open a file for reading. The file must exist.
158 * - "w": Create an empty file for writing. If a file with the same name
159 * already exists its content is erased and the file is treated as a new
160 * empty file.
161 * - "a": Append to a file. Writing operations append data at the end of the
162 * file. The file is created if it does not exist.
163 * - "r+": Open a file for update both reading and writing. The file must
164 * exist.
165 * - "w+": Create an empty file for both reading and writing. If a file with
166 * the same name already exists its content is erased and the file is
167 * treated as a new empty file.
168 * - "a+": Open a file for reading and appending. All writing operations are
169 * performed at the end of the file, protecting the previous content to be
170 * overwritten. You can reposition (fseek, rewind) the internal pointer to
171 * anywhere in the file for reading, but writing operations will move it
172 * back to the end of file. The file is created if it does not exist.
173 *
174 * **NOTE**: In order to open a file as a binary file, a "b" character has to
175 * be included in the `mode` string. This additional "b" character can either
176 * be appended at the end of the string (thus making the following compound
177 * modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the
178 * letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").
179 * Additional characters may follow the sequence, although they should have no
180 * effect. For example, "t" is sometimes appended to make explicit the file is
181 * a text file.
182 *
183 * This function supports Unicode filenames, but they must be encoded in UTF-8
184 * format, regardless of the underlying operating system.
185 *
186 * As a fallback, SDL_RWFromFile() will transparently open a matching filename
187 * in an Android app's `assets`.
188 *
189 * Closing the SDL_RWops will close the file handle SDL is holding internally.
190 *
191 * \param file a UTF-8 string representing the filename to open.
192 * \param mode an ASCII string representing the mode to be used for opening
193 * the file.
194 * \returns a pointer to the SDL_RWops structure that is created, or NULL on
195 * failure; call SDL_GetError() for more information.
196 *
197 * \since This function is available since SDL 2.0.0.
198 *
199 * \sa SDL_RWclose
200 * \sa SDL_RWFromConstMem
201 * \sa SDL_RWFromFP
202 * \sa SDL_RWFromMem
203 * \sa SDL_RWread
204 * \sa SDL_RWseek
205 * \sa SDL_RWtell
206 * \sa SDL_RWwrite
207 */
208extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
209 const char *mode);
210
211#ifdef HAVE_STDIO_H
212
213extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp, SDL_bool autoclose);
214
215#else
216
217/**
218 * Use this function to create an SDL_RWops structure from a standard I/O file
219 * pointer (stdio.h's `FILE*`).
220 *
221 * This function is not available on Windows, since files opened in an
222 * application on that platform cannot be used by a dynamically linked
223 * library.
224 *
225 * On some platforms, the first parameter is a `void*`, on others, it's a
226 * `FILE*`, depending on what system headers are available to SDL. It is
227 * always intended to be the `FILE*` type from the C runtime's stdio.h.
228 *
229 * \param fp the `FILE*` that feeds the SDL_RWops stream.
230 * \param autoclose SDL_TRUE to close the `FILE*` when closing the SDL_RWops,
231 * SDL_FALSE to leave the `FILE*` open when the RWops is
232 * closed.
233 * \returns a pointer to the SDL_RWops structure that is created, or NULL on
234 * failure; call SDL_GetError() for more information.
235 *
236 * \since This function is available since SDL 2.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_RWFromFP(void * fp,
249#endif
250
251/**
252 * Use this function to prepare a read-write memory buffer for use with
253 * SDL_RWops.
254 *
255 * This function sets up an SDL_RWops struct based on a memory area of a
256 * certain size, for both read and write access.
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 make sure the RWops never writes to the memory buffer, you
263 * should use SDL_RWFromConstMem() with a read-only buffer of memory instead.
264 *
265 * \param mem a pointer to a 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 2.0.0.
271 *
272 * \sa SDL_RWclose
273 * \sa SDL_RWFromConstMem
274 * \sa SDL_RWFromFile
275 * \sa SDL_RWFromFP
276 * \sa SDL_RWFromMem
277 * \sa SDL_RWread
278 * \sa SDL_RWseek
279 * \sa SDL_RWtell
280 * \sa SDL_RWwrite
281 */
282extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
283
284/**
285 * Use this function to prepare a read-only memory buffer for use with RWops.
286 *
287 * This function sets up an SDL_RWops struct based on a memory area of a
288 * certain size. It assumes the memory area is not writable.
289 *
290 * Attempting to write to this RWops stream will report an error without
291 * writing to the memory buffer.
292 *
293 * This memory buffer is not copied by the RWops; the pointer you provide must
294 * remain valid until you close the stream. Closing the stream will not free
295 * the original buffer.
296 *
297 * If you need to write to a memory buffer, you should use SDL_RWFromMem()
298 * with a writable buffer of memory instead.
299 *
300 * \param mem a pointer to a read-only buffer to feed an SDL_RWops stream.
301 * \param size the buffer size, in bytes.
302 * \returns a pointer to a new SDL_RWops structure, or NULL if it fails; call
303 * SDL_GetError() for more information.
304 *
305 * \since This function is available since SDL 2.0.0.
306 *
307 * \sa SDL_RWclose
308 * \sa SDL_RWFromConstMem
309 * \sa SDL_RWFromFile
310 * \sa SDL_RWFromFP
311 * \sa SDL_RWFromMem
312 * \sa SDL_RWread
313 * \sa SDL_RWseek
314 * \sa SDL_RWtell
315 */
316extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
317 int size);
318
319/* @} *//* RWFrom functions */
320
321
322/**
323 * Use this function to allocate an empty, unpopulated SDL_RWops structure.
324 *
325 * Applications do not need to use this function unless they are providing
326 * their own SDL_RWops implementation. If you just need a SDL_RWops to
327 * read/write a common data source, you should use the built-in
328 * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc.
329 *
330 * You must free the returned pointer with SDL_FreeRW(). Depending on your
331 * operating system and compiler, there may be a difference between the
332 * malloc() and free() your program uses and the versions SDL calls
333 * internally. Trying to mix the two can cause crashing such as segmentation
334 * faults. Since all SDL_RWops must free themselves when their **close**
335 * method is called, all SDL_RWops must be allocated through this function, so
336 * they can all be freed correctly with SDL_FreeRW().
337 *
338 * \returns a pointer to the allocated memory on success, or NULL on failure;
339 * call SDL_GetError() for more information.
340 *
341 * \since This function is available since SDL 2.0.0.
342 *
343 * \sa SDL_FreeRW
344 */
345extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
346
347/**
348 * Use this function to free an SDL_RWops structure allocated by
349 * SDL_AllocRW().
350 *
351 * Applications do not need to use this function unless they are providing
352 * their own SDL_RWops implementation. If you just need a SDL_RWops to
353 * read/write a common data source, you should use the built-in
354 * implementations in SDL, like SDL_RWFromFile() or SDL_RWFromMem(), etc, and
355 * call the **close** method on those SDL_RWops pointers when you are done
356 * with them.
357 *
358 * Only use SDL_FreeRW() on pointers returned by SDL_AllocRW(). The pointer is
359 * invalid as soon as this function returns. Any extra memory allocated during
360 * creation of the SDL_RWops is not freed by SDL_FreeRW(); the programmer must
361 * be responsible for managing that memory in their **close** method.
362 *
363 * \param area the SDL_RWops structure to be freed.
364 *
365 * \since This function is available since SDL 2.0.0.
366 *
367 * \sa SDL_AllocRW
368 */
369extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
370
371/* Possible `whence` values for SDL_RWops seeking... */
372#define RW_SEEK_SET 0 /**< Seek from the beginning of data */
373#define RW_SEEK_CUR 1 /**< Seek relative to current read point */
374#define RW_SEEK_END 2 /**< Seek relative to the end of data */
375
376/**
377 * Use this function to get the size of the data stream in an SDL_RWops.
378 *
379 * Prior to SDL 2.0.10, this function was a macro.
380 *
381 * \param context the SDL_RWops to get the size of the data stream from.
382 * \returns the size of the data stream in the SDL_RWops on success, -1 if
383 * unknown or a negative error code on failure; call SDL_GetError()
384 * for more information.
385 *
386 * \since This function is available since SDL 2.0.10.
387 */
388extern DECLSPEC Sint64 SDLCALL SDL_RWsize(SDL_RWops *context);
389
390/**
391 * Seek within an SDL_RWops data stream.
392 *
393 * This function seeks to byte `offset`, relative to `whence`.
394 *
395 * `whence` may be any of the following values:
396 *
397 * - `RW_SEEK_SET`: seek from the beginning of data
398 * - `RW_SEEK_CUR`: seek relative to current read point
399 * - `RW_SEEK_END`: seek relative to the end of data
400 *
401 * If this stream can not seek, it will return -1.
402 *
403 * SDL_RWseek() is actually a wrapper function that calls the SDL_RWops's
404 * `seek` method appropriately, to simplify application development.
405 *
406 * Prior to SDL 2.0.10, this function was a macro.
407 *
408 * \param context a pointer to an SDL_RWops structure.
409 * \param offset an offset in bytes, relative to **whence** location; can be
410 * negative.
411 * \param whence any of `RW_SEEK_SET`, `RW_SEEK_CUR`, `RW_SEEK_END`.
412 * \returns the final offset in the data stream after the seek or -1 on error.
413 *
414 * \since This function is available since SDL 2.0.10.
415 *
416 * \sa SDL_RWclose
417 * \sa SDL_RWFromConstMem
418 * \sa SDL_RWFromFile
419 * \sa SDL_RWFromFP
420 * \sa SDL_RWFromMem
421 * \sa SDL_RWread
422 * \sa SDL_RWtell
423 * \sa SDL_RWwrite
424 */
425extern DECLSPEC Sint64 SDLCALL SDL_RWseek(SDL_RWops *context,
426 Sint64 offset, int whence);
427
428/**
429 * Determine the current read/write offset in an SDL_RWops data stream.
430 *
431 * SDL_RWtell is actually a wrapper function that calls the SDL_RWops's `seek`
432 * method, with an offset of 0 bytes from `RW_SEEK_CUR`, to simplify
433 * application development.
434 *
435 * Prior to SDL 2.0.10, this function was a macro.
436 *
437 * \param context a SDL_RWops data stream object from which to get the current
438 * offset.
439 * \returns the current offset in the stream, or -1 if the information can not
440 * be determined.
441 *
442 * \since This function is available since SDL 2.0.10.
443 *
444 * \sa SDL_RWclose
445 * \sa SDL_RWFromConstMem
446 * \sa SDL_RWFromFile
447 * \sa SDL_RWFromFP
448 * \sa SDL_RWFromMem
449 * \sa SDL_RWread
450 * \sa SDL_RWseek
451 * \sa SDL_RWwrite
452 */
453extern DECLSPEC Sint64 SDLCALL SDL_RWtell(SDL_RWops *context);
454
455/**
456 * Read from a data source.
457 *
458 * This function reads up to `maxnum` objects each of size `size` from the
459 * data source to the area pointed at by `ptr`. This function may read less
460 * objects than requested. It will return zero when there has been an error or
461 * the data stream is completely read.
462 *
463 * SDL_RWread() is actually a function wrapper that calls the SDL_RWops's
464 * `read` method appropriately, to simplify application development.
465 *
466 * Prior to SDL 2.0.10, this function was a macro.
467 *
468 * \param context a pointer to an SDL_RWops structure.
469 * \param ptr a pointer to a buffer to read data into.
470 * \param size the size of each object to read, in bytes.
471 * \param maxnum the maximum number of objects to be read.
472 * \returns the number of objects read, or 0 at error or end of file; call
473 * SDL_GetError() for more information.
474 *
475 * \since This function is available since SDL 2.0.10.
476 *
477 * \sa SDL_RWclose
478 * \sa SDL_RWFromConstMem
479 * \sa SDL_RWFromFile
480 * \sa SDL_RWFromFP
481 * \sa SDL_RWFromMem
482 * \sa SDL_RWseek
483 * \sa SDL_RWwrite
484 */
485extern DECLSPEC size_t SDLCALL SDL_RWread(SDL_RWops *context,
486 void *ptr, size_t size,
487 size_t maxnum);
488
489/**
490 * Write to an SDL_RWops data stream.
491 *
492 * This function writes exactly `num` objects each of size `size` from the
493 * area pointed at by `ptr` to the stream. If this fails for any reason, it'll
494 * return less than `num` to demonstrate how far the write progressed. On
495 * success, it returns `num`.
496 *
497 * SDL_RWwrite is actually a function wrapper that calls the SDL_RWops's
498 * `write` method appropriately, to simplify application development.
499 *
500 * Prior to SDL 2.0.10, this function was a macro.
501 *
502 * \param context a pointer to an SDL_RWops structure.
503 * \param ptr a pointer to a buffer containing data to write.
504 * \param size the size of an object to write, in bytes.
505 * \param num the number of objects to write.
506 * \returns the number of objects written, which will be less than **num** on
507 * error; call SDL_GetError() for more information.
508 *
509 * \since This function is available since SDL 2.0.10.
510 *
511 * \sa SDL_RWclose
512 * \sa SDL_RWFromConstMem
513 * \sa SDL_RWFromFile
514 * \sa SDL_RWFromFP
515 * \sa SDL_RWFromMem
516 * \sa SDL_RWread
517 * \sa SDL_RWseek
518 */
519extern DECLSPEC size_t SDLCALL SDL_RWwrite(SDL_RWops *context,
520 const void *ptr, size_t size,
521 size_t num);
522
523/**
524 * Close and free an allocated SDL_RWops structure.
525 *
526 * SDL_RWclose() closes and cleans up the SDL_RWops stream. It releases any
527 * resources used by the stream and frees the SDL_RWops itself with
528 * SDL_FreeRW(). This returns 0 on success, or -1 if the stream failed to
529 * flush to its output (e.g. to disk).
530 *
531 * Note that if this fails to flush the stream to disk, this function reports
532 * an error, but the SDL_RWops is still invalid once this function returns.
533 *
534 * Prior to SDL 2.0.10, this function was a macro.
535 *
536 * \param context SDL_RWops structure to close.
537 * \returns 0 on success or a negative error code on failure; call
538 * SDL_GetError() for more information.
539 *
540 * \since This function is available since SDL 2.0.10.
541 *
542 * \sa SDL_RWFromConstMem
543 * \sa SDL_RWFromFile
544 * \sa SDL_RWFromFP
545 * \sa SDL_RWFromMem
546 * \sa SDL_RWread
547 * \sa SDL_RWseek
548 * \sa SDL_RWwrite
549 */
550extern DECLSPEC int SDLCALL SDL_RWclose(SDL_RWops *context);
551
552/**
553 * Load all the data from an SDL data stream.
554 *
555 * The data is allocated with a zero byte at the end (null terminated) for
556 * convenience. This extra byte is not included in the value reported via
557 * `datasize`.
558 *
559 * The data should be freed with SDL_free().
560 *
561 * \param src the SDL_RWops to read all available data from.
562 * \param datasize if not NULL, will store the number of bytes read.
563 * \param freesrc if non-zero, calls SDL_RWclose() on `src` before returning.
564 * \returns the data, or NULL if there was an error.
565 *
566 * \since This function is available since SDL 2.0.6.
567 */
568extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops *src,
569 size_t *datasize,
570 int freesrc);
571
572/**
573 * Load all the data from a file path.
574 *
575 * The data is allocated with a zero byte at the end (null terminated) for
576 * convenience. This extra byte is not included in the value reported via
577 * `datasize`.
578 *
579 * The data should be freed with SDL_free().
580 *
581 * Prior to SDL 2.0.10, this function was a macro wrapping around
582 * SDL_LoadFile_RW.
583 *
584 * \param file the path to read all available data from.
585 * \param datasize if not NULL, will store the number of bytes read.
586 * \returns the data, or NULL if there was an error.
587 *
588 * \since This function is available since SDL 2.0.10.
589 */
590extern DECLSPEC void *SDLCALL SDL_LoadFile(const char *file, size_t *datasize);
591
592/**
593 * \name Read endian functions
594 *
595 * Read an item of the specified endianness and return in native format.
596 */
597/* @{ */
598
599/**
600 * Use this function to read a byte from an SDL_RWops.
601 *
602 * \param src the SDL_RWops to read from.
603 * \returns the read byte on success or 0 on failure; call SDL_GetError() for
604 * more information.
605 *
606 * \since This function is available since SDL 2.0.0.
607 *
608 * \sa SDL_WriteU8
609 */
610extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
611
612/**
613 * Use this function to read 16 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 16 bits of data in the native byte order of the platform.
621 *
622 * \since This function is available since SDL 2.0.0.
623 *
624 * \sa SDL_ReadBE16
625 */
626extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
627
628/**
629 * Use this function to read 16 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 16 bits of data in the native byte order of the platform.
637 *
638 * \since This function is available since SDL 2.0.0.
639 *
640 * \sa SDL_ReadLE16
641 */
642extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
643
644/**
645 * Use this function to read 32 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 32 bits of data in the native byte order of the platform.
653 *
654 * \since This function is available since SDL 2.0.0.
655 *
656 * \sa SDL_ReadBE32
657 */
658extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
659
660/**
661 * Use this function to read 32 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 32 bits of data in the native byte order of the platform.
669 *
670 * \since This function is available since SDL 2.0.0.
671 *
672 * \sa SDL_ReadLE32
673 */
674extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
675
676/**
677 * Use this function to read 64 bits of little-endian data from an SDL_RWops
678 * and return in native format.
679 *
680 * SDL byteswaps the data only if necessary, so the data returned will be in
681 * the native byte order.
682 *
683 * \param src the stream from which to read data.
684 * \returns 64 bits of data in the native byte order of the platform.
685 *
686 * \since This function is available since SDL 2.0.0.
687 *
688 * \sa SDL_ReadBE64
689 */
690extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
691
692/**
693 * Use this function to read 64 bits of big-endian data from an SDL_RWops and
694 * return in native format.
695 *
696 * SDL byteswaps the data only if necessary, so the data returned will be in
697 * the native byte order.
698 *
699 * \param src the stream from which to read data.
700 * \returns 64 bits of data in the native byte order of the platform.
701 *
702 * \since This function is available since SDL 2.0.0.
703 *
704 * \sa SDL_ReadLE64
705 */
706extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
707/* @} *//* Read endian functions */
708
709/**
710 * \name Write endian functions
711 *
712 * Write an item of native format to the specified endianness.
713 */
714/* @{ */
715
716/**
717 * Use this function to write a byte to an SDL_RWops.
718 *
719 * \param dst the SDL_RWops to write to.
720 * \param value the byte value to write.
721 * \returns 1 on success or 0 on failure; call SDL_GetError() for more
722 * information.
723 *
724 * \since This function is available since SDL 2.0.0.
725 *
726 * \sa SDL_ReadU8
727 */
728extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
729
730/**
731 * Use this function to write 16 bits in native format to a SDL_RWops as
732 * little-endian data.
733 *
734 * SDL byteswaps the data only if necessary, so the application always
735 * specifies native format, and the data written will be in little-endian
736 * format.
737 *
738 * \param dst the stream to which data will be written.
739 * \param value the data to be written, in native format.
740 * \returns 1 on successful write, 0 on error.
741 *
742 * \since This function is available since SDL 2.0.0.
743 *
744 * \sa SDL_WriteBE16
745 */
746extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
747
748/**
749 * Use this function to write 16 bits in native format to a SDL_RWops as
750 * big-endian data.
751 *
752 * SDL byteswaps the data only if necessary, so the application always
753 * specifies native format, and the data written will be in big-endian format.
754 *
755 * \param dst the stream to which data will be written.
756 * \param value the data to be written, in native format.
757 * \returns 1 on successful write, 0 on error.
758 *
759 * \since This function is available since SDL 2.0.0.
760 *
761 * \sa SDL_WriteLE16
762 */
763extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
764
765/**
766 * Use this function to write 32 bits in native format to a SDL_RWops as
767 * little-endian data.
768 *
769 * SDL byteswaps the data only if necessary, so the application always
770 * specifies native format, and the data written will be in little-endian
771 * format.
772 *
773 * \param dst the stream to which data will be written.
774 * \param value the data to be written, in native format.
775 * \returns 1 on successful write, 0 on error.
776 *
777 * \since This function is available since SDL 2.0.0.
778 *
779 * \sa SDL_WriteBE32
780 */
781extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
782
783/**
784 * Use this function to write 32 bits in native format to a SDL_RWops as
785 * big-endian data.
786 *
787 * SDL byteswaps the data only if necessary, so the application always
788 * specifies native format, and the data written will be in big-endian format.
789 *
790 * \param dst the stream to which data will be written.
791 * \param value the data to be written, in native format.
792 * \returns 1 on successful write, 0 on error.
793 *
794 * \since This function is available since SDL 2.0.0.
795 *
796 * \sa SDL_WriteLE32
797 */
798extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
799
800/**
801 * Use this function to write 64 bits in native format to a SDL_RWops as
802 * little-endian data.
803 *
804 * SDL byteswaps the data only if necessary, so the application always
805 * specifies native format, and the data written will be in little-endian
806 * format.
807 *
808 * \param dst the stream to which data will be written.
809 * \param value the data to be written, in native format.
810 * \returns 1 on successful write, 0 on error.
811 *
812 * \since This function is available since SDL 2.0.0.
813 *
814 * \sa SDL_WriteBE64
815 */
816extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
817
818/**
819 * Use this function to write 64 bits in native format to a SDL_RWops as
820 * big-endian data.
821 *
822 * SDL byteswaps the data only if necessary, so the application always
823 * specifies native format, and the data written will be in big-endian format.
824 *
825 * \param dst the stream to which data will be written.
826 * \param value the data to be written, in native format.
827 * \returns 1 on successful write, 0 on error.
828 *
829 * \since This function is available since SDL 2.0.0.
830 *
831 * \sa SDL_WriteLE64
832 */
833extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
834/* @} *//* Write endian functions */
835
836/* Ends C function definitions when using C++ */
837#ifdef __cplusplus
838}
839#endif
840#include "close_code.h"
841
842#endif /* SDL_rwops_h_ */
843
844/* vi: set ts=4 sw=4 expandtab: */
size_t SDL_WriteBE64(SDL_RWops *dst, Uint64 value)
Uint16 SDL_ReadLE16(SDL_RWops *src)
Uint32 SDL_ReadLE32(SDL_RWops *src)
size_t SDL_RWread(SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
SDL_RWops * SDL_RWFromFP(FILE *fp, SDL_bool autoclose)
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)
size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size, size_t num)
SDL_RWops * SDL_RWFromMem(void *mem, int size)
Sint64 SDL_RWtell(SDL_RWops *context)
void SDL_FreeRW(SDL_RWops *area)
void * SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, int freesrc)
Uint64 SDL_ReadLE64(SDL_RWops *src)
SDL_RWops * SDL_AllocRW(void)
Uint64 SDL_ReadBE64(SDL_RWops *src)
size_t SDL_WriteU8(SDL_RWops *dst, Uint8 value)
Uint32 SDL_ReadBE32(SDL_RWops *src)
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)
uint8_t Uint8
Definition SDL_stdinc.h:203
int64_t Sint64
Definition SDL_stdinc.h:238
uint16_t Uint16
Definition SDL_stdinc.h:217
SDL_bool
Definition SDL_stdinc.h:187
uint64_t Uint64
Definition SDL_stdinc.h:245
uint32_t Uint32
Definition SDL_stdinc.h:231
Uint32 type
Definition SDL_rwops.h:95
size_t(* write)(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
Definition SDL_rwops.h:85
struct SDL_RWops::@2::@3::@7 buffer
FILE * fp
Definition SDL_rwops.h:121
SDL_bool autoclose
Definition SDL_rwops.h:120
size_t size
Definition SDL_rwops.h:111
Uint8 * stop
Definition SDL_rwops.h:128
size_t(* read)(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Definition SDL_rwops.h:76
struct SDL_RWops::@2::@5 mem
Uint8 * here
Definition SDL_rwops.h:127
SDL_bool append
Definition SDL_rwops.h:106
size_t left
Definition SDL_rwops.h:112
void * data
Definition SDL_rwops.h:110
int(* close)(struct SDL_RWops *context)
Definition SDL_rwops.h:93
void * h
Definition SDL_rwops.h:107
Sint64(* seek)(struct SDL_RWops *context, Sint64 offset, int whence)
Definition SDL_rwops.h:67
struct SDL_RWops::@2::@4 stdio
void * data1
Definition SDL_rwops.h:132
Sint64(* size)(struct SDL_RWops *context)
Definition SDL_rwops.h:59
struct SDL_RWops::@2::@3 windowsio
union SDL_RWops::@2 hidden
void * data2
Definition SDL_rwops.h:133
struct SDL_RWops::@2::@6 unknown
Uint8 * base
Definition SDL_rwops.h:126