misc.h
Raw
1#ifndef MISC_H
2#define MISC_H
3
4#ifdef __unix__
5 #ifndef _BSD_SOURCE
6 #define _BSD_SOURCE 1
7 #endif
8 #ifndef _DEFAULT_SOURCE
9 #define _DEFAULT_SOURCE 1
10 #endif
11 #include <unistd.h>
12#endif
13#ifdef _WIN32
14 #include <windows.h>
15#endif
16
17#include <string.h>
18#include <cutils/common.h>
19
20#if __STDC_VERSION__ >= 199901L
21 #include <stdint.h>
22 typedef uintmax_t max_uint_t;
23 #ifdef UINT32_MAX
24 uint32_t ntoh32(uint32_t const net);
25 #endif
26#else
27 typedef unsigned long max_uint_t;
28#endif
29
30HEDLEY_INLINE
31static void memswap(void* item1, void* item2, size_t length)
32{
33 char *item1_tmp, *item2_tmp;
34 char tmp;
35
36 item1_tmp = item1;
37 item2_tmp = item2;
38
39 while(length--)
40 {
41 tmp = *item1_tmp;
42 *item1_tmp = *item2_tmp;
43 *item2_tmp = tmp;
44 }
45}
46
47#if __STDC_VERSION__ >= 201112L
48 #include <time.h>
49#endif
50
51void sleep_ms(unsigned int milliseconds);
52
53#if __STDC_VERSION__ >= 201112L
54 struct timespec timespec_diff(const struct timespec* old_ts, const struct timespec* new_ts);
55 struct timespec timespec_add(const struct timespec* ts_1, const struct timespec* ts_2);
56 max_uint_t timespec_ms(const struct timespec* ts);
57#endif
58
59#endif /* MISC_H */
60