1 #ifndef RH_MEMCPY_INLINE_H
 2 #define RH_MEMCPY_INLINE_H 1
 3 
 4 #include <sys/types.h>
 5 #include <stdint.h>
 6 
 7 #define rh_memcpy1(_s1,_s2)                             \
 8         { *((uint8_t*)(_s1))  = *((uint8_t*)(_s2)); }
 9 
10 #define rh_memcpy2(_s1,_s2)                             \
11         { *((uint16_t*)(_s1)) = *((uint16_t*)(_s2)); }
12 
13 #define rh_memcpy3(_s1,_s2)                             \
14         { rh_memcpy1 (_s1, _s2);                        \
15           rh_memcpy2(((uint8_t*)(_s1))+1, ((uint8_t*)(_s2))+1); }
16 
17 #define rh_memcpy4(_s1,_s2)                             \
18         { *((uint32_t*)(_s1)) = *((uint32_t*)(_s2)); }
19 
20 #define rh_memcpy5(_s1,_s2)                             \
21         { rh_memcpy1 (_s1, _s2);                        \
22           rh_memcpy4(((uint8_t*)(_s1))+1, ((uint8_t*)(_s2))+1); }
23 
24 #define rh_memcpy6(_s1,_s2)                             \
25         { rh_memcpy2 (_s1, _s2);                        \
26           rh_memcpy4(((uint16_t*)(_s1))+1, ((uint16_t*)(_s2))+1); }
27 
28 #define rh_memcpy7(_s1,_s2)                             \
29         { rh_memcpy3 (_s1, _s2);                        \
30           rh_memcpy4(((uint8_t*)(_s1))+3, ((uint8_t*)(_s2))+3); }
31 
32 #ifdef HAVE_64BIT
33 # define rh_memcpy8(_s1,_s2)                            \
34         { rh_memcpy4(((uint64_t*)(_s1)), ((uint64_t*)(_s2))); }
35 #else
36 # define rh_memcpy8(_s1,_s2)                            \
37         { rh_memcpy4 (_s1, _s2);                        \
38           rh_memcpy4(((uint32_t*)(_s1))+1, ((uint32_t*)(_s2))+1); }
39 #endif
40 
41 #define rh_memcpy9(_s1,_s2)                             \
42         { rh_memcpy1 (_s1, _s2);                        \
43           rh_memcpy8(((uint8_t*)(_s1))+1, ((uint8_t*)(_s2))+1); }
44 
45 #define rh_memcpy10(_s1,_s2)                            \
46         { rh_memcpy2 (_s1, _s2);                        \
47           rh_memcpy8(((uint8_t*)(_s1))+2, ((uint8_t*)(_s2))+2); }
48 
49 #define rh_memcpy11(_s1,_s2)                            \
50         { rh_memcpy3 (_s1, _s2);                        \
51           rh_memcpy8(((uint8_t*)(_s1))+3, ((uint8_t*)(_s2))+3); }
52 
53 #define rh_memcpy12(_s1,_s2)                            \
54         { rh_memcpy4 (_s1, _s2);                        \
55           rh_memcpy8(((uint32_t*)(_s1))+1, ((uint32_t*)(_s2))+1); }
56 
57 #define rh_memcpy13(_s1,_s2)                            \
58         { rh_memcpy5 (_s1, _s2);                        \
59           rh_memcpy8(((uint8_t*)(_s1))+5, ((uint8_t*)(_s2))+5); }
60 
61 #define rh_memcpy14(_s1,_s2)                            \
62         { rh_memcpy6 (_s1, _s2);                        \
63           rh_memcpy8(((uint8_t*)(_s1))+6, ((uint8_t*)(_s2))+6); }
64 
65 #define rh_memcpy15(_s1,_s2)                            \
66         { rh_memcpy3 (_s1, _s2);                        \
67           rh_memcpy12(((uint8_t*)(_s1))+3, ((uint8_t*)(_s2))+3); }
68 
69 #define rh_memcpy16(_s1,_s2)                            \
70         { rh_memcpy8 (_s1, _s2);                        \
71           rh_memcpy8(((uint32_t*)(_s1))+2, ((uint32_t*)(_s2))+2); }
72 
73 
74 #endif /* ! RH_MEMCPY_INLINE_H */


syntax highlighted by Code2HTML, v. 0.9.1