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. */
| 150 | * host's byte order. Returns 0 on EOF or nonzero on success. |
| 151 | */ |
| 152 | static 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. |
no test coverage detected