SDL_rwops.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #ifndef _SDL_rwops_h
  2. #define _SDL_rwops_h
  3. #include "SDL_stdinc.h"
  4. #include "SDL_error.h"
  5. #include "begin_code.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define SDL_RWOPS_UNKNOWN 0
  10. #define SDL_RWOPS_WINFILE 1
  11. #define SDL_RWOPS_STDFILE 2
  12. #define SDL_RWOPS_JNIFILE 3
  13. #define SDL_RWOPS_MEMORY 4
  14. #define SDL_RWOPS_MEMORY_RO 5
  15. typedef struct SDL_RWops
  16. {
  17. Sint64 (SDLCALL * size) (struct SDL_RWops * context);
  18. Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
  19. int whence);
  20. size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
  21. size_t size, size_t maxnum);
  22. size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
  23. size_t size, size_t num);
  24. int (SDLCALL * close) (struct SDL_RWops * context);
  25. Uint32 type;
  26. union
  27. {
  28. #if defined(ANDROID)
  29. struct
  30. {
  31. void *fileNameRef;
  32. void *inputStreamRef;
  33. void *readableByteChannelRef;
  34. void *readMethod;
  35. void *assetFileDescriptorRef;
  36. long position;
  37. long size;
  38. long offset;
  39. int fd;
  40. } androidio;
  41. #elif defined(__WIN32__)
  42. struct
  43. {
  44. SDL_bool append;
  45. void *h;
  46. struct
  47. {
  48. void *data;
  49. size_t size;
  50. size_t left;
  51. } buffer;
  52. } windowsio;
  53. #endif
  54. #ifdef HAVE_STDIO_H
  55. struct
  56. {
  57. SDL_bool autoclose;
  58. FILE *fp;
  59. } stdio;
  60. #endif
  61. struct
  62. {
  63. Uint8 *base;
  64. Uint8 *here;
  65. Uint8 *stop;
  66. } mem;
  67. struct
  68. {
  69. void *data1;
  70. void *data2;
  71. } unknown;
  72. } hidden;
  73. } SDL_RWops;
  74. typedef SDL_RWops * SDLCALL tSDL_RWFromFile(const char *file,
  75. const char *mode);
  76. #ifdef HAVE_STDIO_H
  77. typedef SDL_RWops * SDLCALL tSDL_RWFromFP(FILE * fp,
  78. SDL_bool autoclose);
  79. #else
  80. typedef SDL_RWops * SDLCALL tSDL_RWFromFP(void * fp,
  81. SDL_bool autoclose);
  82. #endif
  83. typedef SDL_RWops * SDLCALL tSDL_RWFromMem(void *mem, int size);
  84. typedef SDL_RWops * SDLCALL tSDL_RWFromConstMem(const void *mem,
  85. int size);
  86. typedef SDL_RWops * SDLCALL tSDL_AllocRW(void);
  87. typedef void SDLCALL tSDL_FreeRW(SDL_RWops * area);
  88. #define RW_SEEK_SET 0
  89. #define RW_SEEK_CUR 1
  90. #define RW_SEEK_END 2
  91. #define SDL_RWsize(ctx) (ctx)->size(ctx)
  92. #define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
  93. #define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
  94. #define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
  95. #define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
  96. #define SDL_RWclose(ctx) (ctx)->close(ctx)
  97. typedef Uint8 SDLCALL tSDL_ReadU8(SDL_RWops * src);
  98. typedef Uint16 SDLCALL tSDL_ReadLE16(SDL_RWops * src);
  99. typedef Uint16 SDLCALL tSDL_ReadBE16(SDL_RWops * src);
  100. typedef Uint32 SDLCALL tSDL_ReadLE32(SDL_RWops * src);
  101. typedef Uint32 SDLCALL tSDL_ReadBE32(SDL_RWops * src);
  102. typedef Uint64 SDLCALL tSDL_ReadLE64(SDL_RWops * src);
  103. typedef Uint64 SDLCALL tSDL_ReadBE64(SDL_RWops * src);
  104. typedef size_t SDLCALL tSDL_WriteU8(SDL_RWops * dst, Uint8 value);
  105. typedef size_t SDLCALL tSDL_WriteLE16(SDL_RWops * dst, Uint16 value);
  106. typedef size_t SDLCALL tSDL_WriteBE16(SDL_RWops * dst, Uint16 value);
  107. typedef size_t SDLCALL tSDL_WriteLE32(SDL_RWops * dst, Uint32 value);
  108. typedef size_t SDLCALL tSDL_WriteBE32(SDL_RWops * dst, Uint32 value);
  109. typedef size_t SDLCALL tSDL_WriteLE64(SDL_RWops * dst, Uint64 value);
  110. typedef size_t SDLCALL tSDL_WriteBE64(SDL_RWops * dst, Uint64 value);
  111. extern tSDL_RWFromFile *SDL_RWFromFile;
  112. extern tSDL_RWFromFP *SDL_RWFromFP;
  113. extern tSDL_RWFromFP *SDL_RWFromFP;
  114. extern tSDL_RWFromMem *SDL_RWFromMem;
  115. extern tSDL_RWFromConstMem *SDL_RWFromConstMem;
  116. extern tSDL_AllocRW *SDL_AllocRW;
  117. extern tSDL_FreeRW *SDL_FreeRW;
  118. extern tSDL_ReadU8 *SDL_ReadU8;
  119. extern tSDL_ReadLE16 *SDL_ReadLE16;
  120. extern tSDL_ReadBE16 *SDL_ReadBE16;
  121. extern tSDL_ReadLE32 *SDL_ReadLE32;
  122. extern tSDL_ReadBE32 *SDL_ReadBE32;
  123. extern tSDL_ReadLE64 *SDL_ReadLE64;
  124. extern tSDL_ReadBE64 *SDL_ReadBE64;
  125. extern tSDL_WriteU8 *SDL_WriteU8;
  126. extern tSDL_WriteLE16 *SDL_WriteLE16;
  127. extern tSDL_WriteBE16 *SDL_WriteBE16;
  128. extern tSDL_WriteLE32 *SDL_WriteLE32;
  129. extern tSDL_WriteBE32 *SDL_WriteBE32;
  130. extern tSDL_WriteLE64 *SDL_WriteLE64;
  131. extern tSDL_WriteBE64 *SDL_WriteBE64;
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #include "close_code.h"
  136. #endif