Debian Codegraph @

src/file.h

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #ifndef FILE_H
20 #define FILE_Hcxx . . $ `src/file.h:20:9`!
21
22 #include "SDL_endian.h"
23
24 #include <stdbool.h>
25 #include <stdio.h>
26
27 extern const char *custom_data_dircxx . . $ custom_data_dir.;
28
29 const char *data_dircxx . . $ data_dir(33a1f659e94feb42).(void);
30
31 FILEcxx . . $ FILE# *dir_fopencxx . . $ dir_fopen(2493aa730c89ee72).(const char *dir, const char *file, const char *mode);
32 FILEcxx . . $ FILE# *dir_fopen_warncxx . . $ dir_fopen_warn(2493aa730c89ee72).(const char *dir, const char *file, const char *mode);
33 FILEcxx . . $ FILE# *dir_fopen_diecxx . . $ dir_fopen_die(2493aa730c89ee72).(const char *dir, const char *file, const char *mode);
34
35 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! dir_file_existscxx . . $ dir_file_exists(b7a7aa4a824b7595).(const char *dir, const char *file);
36
37 long ftell_eofcxx . . $ ftell_eof(1dcafcd8ef4c6e6c).(FILEcxx . . $ FILE# *f);
38
39 void fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(void *buffer, size_tcxx . . $ size_t# size, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream);
40
41 // 8-bit fread that dies if read fails
42 static inline void fread_bool_diecxx . . $ fread_bool_die(907b9e3ee78d059).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *buffer, FILEcxx . . $ FILE# *stream)
43 {
44 Uint8cxx . . $ Uint8# temp;
45 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(&temp, sizeof(Uint8cxx . . $ Uint8#), 1, stream);
46 *buffer = temp != 0;
47 }
48
49 // 8-bit fread
50 static inline size_tcxx . . $ size_t# fread_u8cxx . . $ fread_u8(e379f1355fd4067).(Uint8cxx . . $ Uint8# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
51 {
52 return freadcxx . . $ fread(738fc8ac1d711e58).(buffer, sizeof(Uint8cxx . . $ Uint8#), count, stream);
53 }
54
55 // 8-bit fread that dies if read fails
56 static inline void fread_u8_diecxx . . $ fread_u8_die(77ebc59a7bf9f340).(Uint8cxx . . $ Uint8# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
57 {
58 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(buffer, sizeof(Uint8cxx . . $ Uint8#), count, stream);
59 }
60
61 // 8-bit fread that dies if read fails
62 static inline void fread_s8_diecxx . . $ fread_s8_die(dc08b0f48459588a).(Sint8cxx . . $ Sint8# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
63 {
64 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(buffer, sizeof(Sint8cxx . . $ Sint8#), count, stream);
65 }
66
67 // 16-bit endian-swapping fread that dies if read fails
68 static inline void fread_u16_diecxx . . $ fread_u16_die(c6228d4965a46ad0).(Uint16cxx . . $ Uint16# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
69 {
70 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(buffer, sizeof(Uint16cxx . . $ Uint16#), count, stream);
71
72 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
73 for (size_t i = 0; i < count; ++i)
74 buffer[i] = SDL_Swap16(buffer[i]);
75 #endif
76 }
77
78 // 16-bit endian-swapping fread that dies if read fails
79 static inline void fread_s16_diecxx . . $ fread_s16_die(1003bcb2988c104e).(Sint16cxx . . $ Sint16# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
80 {
81 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(buffer, sizeof(Sint16cxx . . $ Sint16#), count, stream);
82
83 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
84 for (size_t i = 0; i < count; ++i)
85 buffer[i] = SDL_Swap16(buffer[i]);
86 #endif
87 }
88
89 // 32-bit endian-swapping fread that dies if read fails
90 static inline void fread_u32_diecxx . . $ fread_u32_die(503b8e976a020473).(Uint32cxx . . $ Uint32# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
91 {
92 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(buffer, sizeof(Uint32cxx . . $ Uint32#), count, stream);
93
94 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
95 for (size_t i = 0; i < count; ++i)
96 buffer[i] = SDL_Swap32(buffer[i]);
97 #endif
98 }
99
100 // 32-bit endian-swapping fread that dies if read fails
101 static inline void fread_s32_diecxx . . $ fread_s32_die(4b35c8e6f923dc9d).(Sint32cxx . . $ Sint32# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
102 {
103 fread_diecxx . . $ fread_die(82d71c9ec5b61e0f).(buffer, sizeof(Sint32cxx . . $ Sint32#), count, stream);
104
105 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
106 for (size_t i = 0; i < count; ++i)
107 buffer[i] = SDL_Swap32(buffer[i]);
108 #endif
109 }
110
111 void fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(const void *buffer, size_tcxx . . $ size_t# size, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream);
112
113 // 8-bit fwrite that dies if write fails
114 static inline void fwrite_bool_diecxx . . $ fwrite_bool_die(d02cc9ace855460f).(const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *buffer, FILEcxx . . $ FILE# *stream)
115 {
116 Uint8cxx . . $ Uint8# temp = *buffer ? 1 : 0;
117 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(&temp, sizeof(Uint8cxx . . $ Uint8#), 1, stream);
118 }
119
120 // 8-bit fwrite
121 static inline size_tcxx . . $ size_t# fwrite_u8cxx . . $ fwrite_u8(a2b46a5ad1e95f29).(const Uint8cxx . . $ Uint8# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
122 {
123 return fwritecxx . . $ fwrite(ab0609fa07c47d6e).(buffer, sizeof(Uint8cxx . . $ Uint8#), count, stream);
124 }
125
126 // 8-bit fwrite that dies if write fails
127 static inline void fwrite_u8_diecxx . . $ fwrite_u8_die(a9c0feb52dde6622).(const Uint8cxx . . $ Uint8# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
128 {
129 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(buffer, sizeof(Uint8cxx . . $ Uint8#), count, stream);
130 }
131
132 // 8-bit fwrite that dies if write fails
133 static inline void fwrite_s8_diecxx . . $ fwrite_s8_die(c6d81d9f7f466d04).(const Sint8cxx . . $ Sint8# *buffer, size_tcxx . . $ size_t# count, FILEcxx . . $ FILE# *stream)
134 {
135 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(buffer, sizeof(Sint8cxx . . $ Sint8#), count, stream);
136 }
137
138 // 16-bit endian-swapping fwrite that dies if write fails
139 static inline void fwrite_u16_diecxx . . $ fwrite_u16_die(79016506b65b1ae8).(const Uint16cxx . . $ Uint16# *buffer, FILEcxx . . $ FILE# *stream)
140 {
141 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
142 Uint16 temp = SDL_Swap16(*buffer);
143 buffer = &temp;
144 #endif
145
146 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(buffer, sizeof(Uint16cxx . . $ Uint16#), 1, stream);
147 }
148
149 // 16-bit endian-swapping fwrite that dies if write fails
150 static inline void fwrite_s16_diecxx . . $ fwrite_s16_die(831b0f32e313b4bc).(const Sint16cxx . . $ Sint16# *buffer, FILEcxx . . $ FILE# *stream)
151 {
152 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
153 Sint16 temp = SDL_Swap16(*buffer);
154 buffer = &temp;
155 #endif
156
157 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(buffer, sizeof(Sint16cxx . . $ Sint16#), 1, stream);
158 }
159
160 // 32-bit endian-swapping fwrite that dies if write fails
161 static inline void fwrite_u32_diecxx . . $ fwrite_u32_die(1e5ff77eac55f20c).(const Uint32cxx . . $ Uint32# *buffer, FILEcxx . . $ FILE# *stream)
162 {
163 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
164 Uint32 temp = SDL_Swap32(*buffer);
165 buffer = &temp;
166 #endif
167
168 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(buffer, sizeof(Uint32cxx . . $ Uint32#), 1, stream);
169 }
170
171 // 32-bit endian-swapping fwrite that dies if write fails
172 static inline void fwrite_s32_diecxx . . $ fwrite_s32_die(820541619cc9150d).(const Sint32cxx . . $ Sint32# *buffer, FILEcxx . . $ FILE# *stream)
173 {
174 #if SDL_BYTEORDERcxx . . $ `<external>/7875807700584907893/SDL_endian.h:61:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/7875807700584907893/SDL_endian.h:55:9`!
175 Sint32 temp = SDL_Swap32(*buffer);
176 buffer = &temp;
177 #endif
178
179 fwrite_diecxx . . $ fwrite_die(8541cce38b5beb5e).(buffer, sizeof(Sint32cxx . . $ Sint32#), 1, stream);
180 }
181
182 #endif // FILE_H