Mercurial > hg > forks > yadex
comparison src/wads.cc @ 109:f05330267c66
Use stdint types.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Oct 2014 12:59:23 +0300 |
parents | 002bc70a3982 |
children |
comparison
equal
deleted
inserted
replaced
108:c91965fc33b6 | 109:f05330267c66 |
---|---|
32 #include "serialnum.h" | 32 #include "serialnum.h" |
33 #include "wads.h" | 33 #include "wads.h" |
34 | 34 |
35 | 35 |
36 /* | 36 /* |
37 * file_read_i16 - read little-endian 16-bit signed integers from a file | 37 * file_read_int16_t - read little-endian 16-bit signed integers from a file |
38 * | 38 * |
39 * Return 0 on success, non-zero on failure. | 39 * Return 0 on success, non-zero on failure. |
40 */ | 40 */ |
41 int file_read_i16(FILE * fp, i16 * buf, long count) | 41 int file_read_i16(FILE * fp, int16_t * buf, long count) |
42 { | 42 { |
43 while (count-- > 0) | 43 while (count-- > 0) |
44 *buf = getc(fp) | (getc(fp) << 8); | 44 *buf = getc(fp) | (getc(fp) << 8); |
45 return feof(fp) || ferror(fp); | 45 return feof(fp) || ferror(fp); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 /* | 49 /* |
50 * file_read_i32 - read little-endian 32-bit signed integers from a file | 50 * file_read_int32_t - read little-endian 32-bit signed integers from a file |
51 * | 51 * |
52 * Return 0 on success, non-zero on failure. | 52 * Return 0 on success, non-zero on failure. |
53 */ | 53 */ |
54 int file_read_i32(FILE * fp, i32 * buf, long count) | 54 int file_read_i32(FILE * fp, int32_t * buf, long count) |
55 { | 55 { |
56 while (count-- > 0) | 56 while (count-- > 0) |
57 { | 57 { |
58 *buf++ = getc(fp) | 58 *buf++ = getc(fp) |
59 | (getc(fp) << 8) | 59 | (getc(fp) << 8) |
60 | ((i32) getc(fp) << 16) | ((i32) getc(fp) << 24); | 60 | ((int32_t) getc(fp) << 16) | ((int32_t) getc(fp) << 24); |
61 } | 61 } |
62 return feof(fp) || ferror(fp); | 62 return feof(fp) || ferror(fp); |
63 } | 63 } |
64 | 64 |
65 | 65 |
101 return file_read_vbytes(fp, buf, count) != count; | 101 return file_read_vbytes(fp, buf, count) != count; |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 /* | 105 /* |
106 * file_write_i16 - write a little-endian 16-bit signed integer to a file | 106 * file_write_int16_t - write a little-endian 16-bit signed integer to a file |
107 * | 107 * |
108 * Does no error checking. | 108 * Does no error checking. |
109 */ | 109 */ |
110 void file_write_i16(FILE * fd, i16 buf) | 110 void file_write_i16(FILE * fd, int16_t buf) |
111 { | 111 { |
112 putc(buf & 0xff, fd); | 112 putc(buf & 0xff, fd); |
113 putc((buf >> 8) & 0xff, fd); | 113 putc((buf >> 8) & 0xff, fd); |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 /* | 117 /* |
118 * file_write_i32 - write little-endian 32-bit signed integers to a file | 118 * file_write_int32_t - write little-endian 32-bit signed integers to a file |
119 * | 119 * |
120 * Does no error checking. | 120 * Does no error checking. |
121 */ | 121 */ |
122 void file_write_i32(FILE * fd, i32 buf, long count) | 122 void file_write_i32(FILE * fd, int32_t buf, long count) |
123 { | 123 { |
124 /* It would probably be more efficient to swap bytes in-core | 124 /* It would probably be more efficient to swap bytes in-core |
125 and write the whole i32 at once. */ | 125 and write the whole int32_t at once. */ |
126 while (count-- > 0) | 126 while (count-- > 0) |
127 { | 127 { |
128 putc(buf & 0xff, fd); | 128 putc(buf & 0xff, fd); |
129 putc((buf >> 8) & 0xff, fd); | 129 putc((buf >> 8) & 0xff, fd); |
130 putc((buf >> 16) & 0xff, fd); | 130 putc((buf >> 16) & 0xff, fd); |