All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ndn_memory.h
1 
21 /*
22  * Based on NDN_CPP_HAVE_MEMCMP, NDN_CPP_HAVE_MEMCPY and NDN_CPP_HAVE_MEMSET in
23  * ndn-cpp-config.h, use the library version or a local implementation of
24  * memcmp, memcpy and memset.
25  */
26 
27 #ifndef NDN_MEMORY_H
28 #define NDN_MEMORY_H
29 
30 #include <ndn-cpp/c/common.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #if NDN_CPP_HAVE_MEMCMP
37 
38 #if NDN_CPP_HAVE_MEMORY_H
39 #include <memory.h>
40 #else
41 #include <string.h>
42 #endif
43 
46 static __inline int ndn_memcmp(const uint8_t *buf1, const uint8_t *buf2, size_t len)
47 {
48  if (len == 0)
49  // Allow buf1 or buf2 to be null.
50  return 0;
51  else
52  return memcmp(buf1, buf2, len);
53 }
54 #else
55 
58 int ndn_memcmp(const uint8_t *buf1, const uint8_t *buf2, size_t len);
59 #endif
60 
61 #if NDN_CPP_HAVE_MEMCPY
62 
63 #if NDN_CPP_HAVE_MEMORY_H
64 #include <memory.h>
65 #else
66 #include <string.h>
67 #endif
68 
71 static __inline void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len)
72 {
73  // If len == 0, allow dest or src to be null.
74  if (len > 0)
75  memcpy(dest, src, len);
76 }
77 #else
78 
81 void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len);
82 #endif
83 
84 #if NDN_CPP_HAVE_MEMSET
85 
86 #if NDN_CPP_HAVE_MEMORY_H
87 #include <memory.h>
88 #else
89 #include <string.h>
90 #endif
91 
94 static __inline void ndn_memset(uint8_t *dest, int val, size_t len)
95 {
96  // If len == 0, allow dest to be null.
97  if (len > 0)
98  memset(dest, val, len);
99 }
100 #else
101 
104 void ndn_memset(uint8_t *dest, int val, size_t len);
105 #endif
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif
112