22#include "SDL_endian.h"
27extern const char *custom_data_dir;
29const char *data_dir(
void);
31FILE *dir_fopen(
const char *dir,
const char *file,
const char *mode);
32FILE *dir_fopen_warn(
const char *dir,
const char *file,
const char *mode);
33FILE *dir_fopen_die(
const char *dir,
const char *file,
const char *mode);
35bool dir_file_exists(
const char *dir,
const char *file);
37long ftell_eof(FILE *f);
39void fread_die(
void *buffer,
size_t size,
size_t count, FILE *stream);
42static inline void fread_bool_die(
bool *buffer, FILE *stream)
45 fread_die(&temp,
sizeof(Uint8), 1, stream);
50static inline size_t fread_u8(Uint8 *buffer,
size_t count, FILE *stream)
52 return fread(buffer,
sizeof(Uint8), count, stream);
56static inline void fread_u8_die(Uint8 *buffer,
size_t count, FILE *stream)
58 fread_die(buffer,
sizeof(Uint8), count, stream);
62static inline void fread_s8_die(Sint8 *buffer,
size_t count, FILE *stream)
64 fread_die(buffer,
sizeof(Sint8), count, stream);
68static inline void fread_u16_die(Uint16 *buffer,
size_t count, FILE *stream)
70 fread_die(buffer,
sizeof(Uint16), count, stream);
72#if SDL_BYTEORDER == SDL_BIG_ENDIAN
73 for (
size_t i = 0; i < count; ++i)
74 buffer[i] = SDL_Swap16(buffer[i]);
79static inline void fread_s16_die(Sint16 *buffer,
size_t count, FILE *stream)
81 fread_die(buffer,
sizeof(Sint16), count, stream);
83#if SDL_BYTEORDER == SDL_BIG_ENDIAN
84 for (
size_t i = 0; i < count; ++i)
85 buffer[i] = SDL_Swap16(buffer[i]);
90static inline void fread_u32_die(Uint32 *buffer,
size_t count, FILE *stream)
92 fread_die(buffer,
sizeof(Uint32), count, stream);
94#if SDL_BYTEORDER == SDL_BIG_ENDIAN
95 for (
size_t i = 0; i < count; ++i)
96 buffer[i] = SDL_Swap32(buffer[i]);
101static inline void fread_s32_die(Sint32 *buffer,
size_t count, FILE *stream)
103 fread_die(buffer,
sizeof(Sint32), count, stream);
105#if SDL_BYTEORDER == SDL_BIG_ENDIAN
106 for (
size_t i = 0; i < count; ++i)
107 buffer[i] = SDL_Swap32(buffer[i]);
111void fwrite_die(
const void *buffer,
size_t size,
size_t count, FILE *stream);
114static inline void fwrite_bool_die(
const bool *buffer, FILE *stream)
116 Uint8 temp = *buffer ? 1 : 0;
117 fwrite_die(&temp,
sizeof(Uint8), 1, stream);
121static inline size_t fwrite_u8(
const Uint8 *buffer,
size_t count, FILE *stream)
123 return fwrite(buffer,
sizeof(Uint8), count, stream);
127static inline void fwrite_u8_die(
const Uint8 *buffer,
size_t count, FILE *stream)
129 fwrite_die(buffer,
sizeof(Uint8), count, stream);
133static inline void fwrite_s8_die(
const Sint8 *buffer,
size_t count, FILE *stream)
135 fwrite_die(buffer,
sizeof(Sint8), count, stream);
139static inline void fwrite_u16_die(
const Uint16 *buffer, FILE *stream)
141#if SDL_BYTEORDER == SDL_BIG_ENDIAN
142 Uint16 temp = SDL_Swap16(*buffer);
146 fwrite_die(buffer,
sizeof(Uint16), 1, stream);
150static inline void fwrite_s16_die(
const Sint16 *buffer, FILE *stream)
152#if SDL_BYTEORDER == SDL_BIG_ENDIAN
153 Sint16 temp = SDL_Swap16(*buffer);
157 fwrite_die(buffer,
sizeof(Sint16), 1, stream);
161static inline void fwrite_u32_die(
const Uint32 *buffer, FILE *stream)
163#if SDL_BYTEORDER == SDL_BIG_ENDIAN
164 Uint32 temp = SDL_Swap32(*buffer);
168 fwrite_die(buffer,
sizeof(Uint32), 1, stream);
172static inline void fwrite_s32_die(
const Sint32 *buffer, FILE *stream)
174#if SDL_BYTEORDER == SDL_BIG_ENDIAN
175 Sint32 temp = SDL_Swap32(*buffer);
179 fwrite_die(buffer,
sizeof(Sint32), 1, stream);