blob: e7f648078e078e98a1cc9747a2dfdaf49f392314 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompsonf418fe02013-06-27 17:28:55 -07004 */
5
6/*
Jeff Thompson7ca936b2013-07-11 12:43:44 -07007 * Based on HAVE_MEMCPY and HAVE_MEMSET in config.h, use the library version or a local implementation of memcmp, memcpy and memset.
Jeff Thompsonf418fe02013-06-27 17:28:55 -07008 */
9
10#ifndef NDN_MEMORY_H
Jeff Thompsona0d18c92013-08-06 13:55:32 -070011#define NDN_MEMORY_H
Jeff Thompsonf418fe02013-06-27 17:28:55 -070012
Jeff Thompson6cb56f92013-07-01 15:38:09 -070013#include "../../../config.h"
Jeff Thompsonf418fe02013-06-27 17:28:55 -070014
Jeff Thompsona0d18c92013-08-06 13:55:32 -070015#ifdef __cplusplus
Jeff Thompsonf418fe02013-06-27 17:28:55 -070016extern "C" {
17#endif
18
Jeff Thompsond4a1e162013-07-11 12:41:31 -070019#if HAVE_MEMCMP
20#include <memory.h>
21/**
22 * Use the library version of memcmp.
23 */
Jeff Thompson2f0bd002013-08-16 18:58:19 -070024static inline int ndn_memcmp(unsigned char *buf1, unsigned char *buf2, unsigned int len) { return memcmp(buf1, buf2, len); }
Jeff Thompsond4a1e162013-07-11 12:41:31 -070025#else
26/**
27 * Use a local implementation of memcmp instead of the library version.
28 */
29int ndn_memcmp(unsigned char *buf1, unsigned char *buf2, unsigned int len);
30#endif
31
Jeff Thompsonf418fe02013-06-27 17:28:55 -070032#if HAVE_MEMCPY
33#include <memory.h>
34/**
35 * Use the library version of memcpy.
36 */
37static inline void ndn_memcpy(unsigned char *dest, unsigned char *src, unsigned int len) { memcpy(dest, src, len); }
38#else
39/**
40 * Use a local implementation of memcpy instead of the library version.
41 */
42void ndn_memcpy(unsigned char *dest, unsigned char *src, unsigned int len);
43#endif
44
45#if HAVE_MEMSET
46#include <memory.h>
47/**
48 * Use the library version of memset.
49 */
50static inline void ndn_memset(unsigned char *dest, int val, unsigned int len) { memset(dest, val, len); }
51#else
52/**
53 * Use a local implementation of memset instead of the library version.
54 */
55void ndn_memset(unsigned char *dest, int val, unsigned int len);
56#endif
57
Jeff Thompsona0d18c92013-08-06 13:55:32 -070058#ifdef __cplusplus
Jeff Thompsonf418fe02013-06-27 17:28:55 -070059}
60#endif
61
62#endif
63