diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/util.c | 58 | ||||
-rw-r--r-- | toxcore/util.h | 13 |
2 files changed, 0 insertions, 71 deletions
diff --git a/toxcore/util.c b/toxcore/util.c index 969ee704..ee4fa3b2 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -133,61 +133,3 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
133 | 133 | ||
134 | return length == 0 ? 0 : -1; | 134 | return length == 0 ? 0 : -1; |
135 | }; | 135 | }; |
136 | |||
137 | /* Converts 4 bytes to uint32_t */ | ||
138 | inline__ void bytes_to_U32(uint32_t *dest, const uint8_t *bytes) | ||
139 | { | ||
140 | *dest = | ||
141 | #ifdef WORDS_BIGENDIAN | ||
142 | ( ( uint32_t ) * bytes ) | | ||
143 | ( ( uint32_t ) * ( bytes + 1 ) << 8 ) | | ||
144 | ( ( uint32_t ) * ( bytes + 2 ) << 16 ) | | ||
145 | ( ( uint32_t ) * ( bytes + 3 ) << 24 ) ; | ||
146 | #else | ||
147 | ( ( uint32_t ) * bytes << 24 ) | | ||
148 | ( ( uint32_t ) * ( bytes + 1 ) << 16 ) | | ||
149 | ( ( uint32_t ) * ( bytes + 2 ) << 8 ) | | ||
150 | ( ( uint32_t ) * ( bytes + 3 ) ) ; | ||
151 | #endif | ||
152 | } | ||
153 | |||
154 | /* Converts 2 bytes to uint16_t */ | ||
155 | inline__ void bytes_to_U16(uint16_t *dest, const uint8_t *bytes) | ||
156 | { | ||
157 | *dest = | ||
158 | #ifdef WORDS_BIGENDIAN | ||
159 | ( ( uint16_t ) * bytes ) | | ||
160 | ( ( uint16_t ) * ( bytes + 1 ) << 8 ); | ||
161 | #else | ||
162 | ( ( uint16_t ) * bytes << 8 ) | | ||
163 | ( ( uint16_t ) * ( bytes + 1 ) ); | ||
164 | #endif | ||
165 | } | ||
166 | |||
167 | /* Convert uint32_t to byte string of size 4 */ | ||
168 | inline__ void U32_to_bytes(uint8_t *dest, uint32_t value) | ||
169 | { | ||
170 | #ifdef WORDS_BIGENDIAN | ||
171 | *(dest) = ( value ); | ||
172 | *(dest + 1) = ( value >> 8 ); | ||
173 | *(dest + 2) = ( value >> 16 ); | ||
174 | *(dest + 3) = ( value >> 24 ); | ||
175 | #else | ||
176 | *(dest) = ( value >> 24 ); | ||
177 | *(dest + 1) = ( value >> 16 ); | ||
178 | *(dest + 2) = ( value >> 8 ); | ||
179 | *(dest + 3) = ( value ); | ||
180 | #endif | ||
181 | } | ||
182 | |||
183 | /* Convert uint16_t to byte string of size 2 */ | ||
184 | inline__ void U16_to_bytes(uint8_t *dest, uint16_t value) | ||
185 | { | ||
186 | #ifdef WORDS_BIGENDIAN | ||
187 | *(dest) = ( value ); | ||
188 | *(dest + 1) = ( value >> 8 ); | ||
189 | #else | ||
190 | *(dest) = ( value >> 8 ); | ||
191 | *(dest + 1) = ( value ); | ||
192 | #endif | ||
193 | } \ No newline at end of file | ||
diff --git a/toxcore/util.h b/toxcore/util.h index 955ce8c4..7992a985 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -47,17 +47,4 @@ typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32 | |||
47 | int load_state(load_state_callback_func load_state_callback, void *outer, | 47 | int load_state(load_state_callback_func load_state_callback, void *outer, |
48 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); | 48 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); |
49 | 49 | ||
50 | /* Converts 4 bytes to uint32_t */ | ||
51 | void bytes_to_U32(uint32_t *dest, const uint8_t *bytes); | ||
52 | |||
53 | /* Converts 2 bytes to uint16_t */ | ||
54 | void bytes_to_U16(uint16_t *dest, const uint8_t *bytes); | ||
55 | |||
56 | /* Convert uint32_t to byte string of size 4 */ | ||
57 | void U32_to_bytes(uint8_t *dest, uint32_t value); | ||
58 | |||
59 | /* Convert uint16_t to byte string of size 2 */ | ||
60 | void U16_to_bytes(uint8_t *dest, uint16_t value); | ||
61 | |||
62 | |||
63 | #endif /* __UTIL_H__ */ | 50 | #endif /* __UTIL_H__ */ |