MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / ReadLittleInt32

Function ReadLittleInt32

include/bmpread/bmpread.c:152–171  ·  view source on GitHub ↗

Reads a little-endian int32_t from fp and stores the result in *dest in the * host's byte order. Returns 0 on EOF or nonzero on success. */

Source from the content-addressed store, hash-verified

150 * host's byte order. Returns 0 on EOF or nonzero on success.
151 */
152static int ReadLittleInt32(int32_t * dest, FILE * fp)
153{
154 /* I *believe* casting unsigned -> signed is implementation-defined when
155 * the unsigned value is out of range for the signed type, which would be
156 * the case for any negative number we've just read out of the file into a
157 * uint. This is a portable way to "reinterpret" the bits as signed
158 * without running into undefined/implementation-defined behavior. I
159 * think.
160 */
161 union int32_signedness_swap
162 {
163 uint32_t uint32;
164 int32_t int32;
165
166 } t;
167
168 if(!ReadLittleBytes(&t.uint32, 4, fp)) return 0;
169 *dest = t.int32;
170 return 1;
171}
172
173/* Reads a little-endian uint16_t from fp and stores the result in *dest in the
174 * host's byte order. Returns 0 on EOF or nonzero n success.

Callers 1

ReadInfoFunction · 0.85

Calls 1

ReadLittleBytesFunction · 0.85

Tested by

no test coverage detected