blob: 27b552d0556ecd6be06e21aa4f6c52797f264730 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompsonf418fe02013-06-27 17:28:55 -07005 */
6
7/*
Jeff Thompsonb7523002013-10-09 10:25:00 -07008 * Based on NDN_CPP_HAVE_MEMCPY and NDN_CPP_HAVE_MEMSET in ndn-cpp-config.h, use the library version or a local implementation of memcmp, memcpy and memset.
Jeff Thompsonf418fe02013-06-27 17:28:55 -07009 */
10
11#ifndef NDN_MEMORY_H
Jeff Thompsona0d18c92013-08-06 13:55:32 -070012#define NDN_MEMORY_H
Jeff Thompsonf418fe02013-06-27 17:28:55 -070013
Yingdi Yu61ec2722014-01-20 14:22:32 -080014#include <ndn-cpp-dev/c/common.h>
Jeff Thompsonf418fe02013-06-27 17:28:55 -070015
Jeff Thompsona0d18c92013-08-06 13:55:32 -070016#ifdef __cplusplus
Jeff Thompsonf418fe02013-06-27 17:28:55 -070017extern "C" {
18#endif
19
Jeff Thompsonb7523002013-10-09 10:25:00 -070020#if NDN_CPP_HAVE_MEMCMP
Jeff Thompsond4a1e162013-07-11 12:41:31 -070021#include <memory.h>
22/**
23 * Use the library version of memcmp.
24 */
Alexander Afanasyevc94a7832014-01-03 13:22:38 -080025static inline int ndn_memcmp(const uint8_t *buf1, const uint8_t *buf2, size_t len) { return memcmp(buf1, buf2, len); }
Jeff Thompsond4a1e162013-07-11 12:41:31 -070026#else
27/**
28 * Use a local implementation of memcmp instead of the library version.
29 */
Jeff Thompson97223af2013-09-24 17:01:27 -070030int ndn_memcmp(uint8_t *buf1, uint8_t *buf2, size_t len);
Jeff Thompsond4a1e162013-07-11 12:41:31 -070031#endif
32
Jeff Thompsonb7523002013-10-09 10:25:00 -070033#if NDN_CPP_HAVE_MEMCPY
Jeff Thompsonf418fe02013-06-27 17:28:55 -070034#include <memory.h>
35/**
36 * Use the library version of memcpy.
37 */
Alexander Afanasyevc94a7832014-01-03 13:22:38 -080038static inline void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len) { memcpy(dest, src, len); }
Jeff Thompsonf418fe02013-06-27 17:28:55 -070039#else
40/**
41 * Use a local implementation of memcpy instead of the library version.
42 */
Alexander Afanasyevc94a7832014-01-03 13:22:38 -080043void ndn_memcpy(uint8_t *dest, const uint8_t *src, size_t len);
Jeff Thompsonf418fe02013-06-27 17:28:55 -070044#endif
45
Jeff Thompsonb7523002013-10-09 10:25:00 -070046#if NDN_CPP_HAVE_MEMSET
Jeff Thompsonf418fe02013-06-27 17:28:55 -070047#include <memory.h>
48/**
49 * Use the library version of memset.
50 */
Jeff Thompson97223af2013-09-24 17:01:27 -070051static inline void ndn_memset(uint8_t *dest, int val, size_t len) { memset(dest, val, len); }
Jeff Thompsonf418fe02013-06-27 17:28:55 -070052#else
53/**
54 * Use a local implementation of memset instead of the library version.
55 */
Jeff Thompson97223af2013-09-24 17:01:27 -070056void ndn_memset(uint8_t *dest, int val, size_t len);
Jeff Thompsonf418fe02013-06-27 17:28:55 -070057#endif
58
Jeff Thompsona0d18c92013-08-06 13:55:32 -070059#ifdef __cplusplus
Jeff Thompsonf418fe02013-06-27 17:28:55 -070060}
61#endif
62
63#endif
64