forked from heinrich5991/libtw2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_inlines.h
80 lines (66 loc) · 1.78 KB
/
common_inlines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <string.h>
static inline void tw_str_copy(char *dst, const char *src, size_t dst_size)
{
strncpy(dst, src, dst_size);
dst[dst_size - 1] = 0; // null termination
}
static inline void tw_str_append(char *dst, const char *src, size_t dst_size)
{
unsigned len = strlen(dst);
if(len < dst_size)
strncpy(dst + len, src, dst_size - len);
dst[dst_size - 1] = 0;
}
static inline int tw_str_comp(const char *str1, const char *str2)
{
return strcmp(str1, str2);
}
static inline size_t tw_str_length(const char *str)
{
return strlen(str);
}
static inline void tw_mem_copy(void *dst, const void *src, size_t size)
{
memcpy(dst, src, size);
}
static inline void tw_mem_move(void *dst, const void *src, size_t size)
{
memmove(dst, src, size);
}
static inline int tw_mem_comp(const void *mem1, const void *mem2, size_t size)
{
return memcmp(mem1, mem2, size);
}
static inline void tw_mem_zero(void *mem, size_t size)
{
memset(mem, 0, size);
}
static inline void tw_str_format(char *dst, size_t dst_size, const char *fmt, ...)
{
va_list va_args;
va_start(va_args, fmt);
tw_str_format_v(dst, dst_size, fmt, va_args);
va_end(va_args);
}
static inline void tw_str_format_v(char *dst, size_t dst_size, const char *fmt, va_list va_args)
{
vsnprintf(dst, dst_size, fmt, va_args);
dst[dst_size - 1] = 0; // null termination
}
static inline void tw_endian_tolittle(void *data, size_t size, int count)
{
(void)data; (void)size; (void)count;
}
static inline void tw_endian_tobig(void *data, size_t size, int count)
{
tw_endian_swap(data, size, count);
}
static inline void tw_endian_fromlittle(void *data, size_t size, int count)
{
(void)data; (void)size; (void)count;
}
static inline void tw_endian_frombig(void *data, size_t size, int count)
{
tw_endian_swap(data, size, count);
}