1/* 2 * Copyright (c) 2010 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * ccMemory.h 26 * CommonCrypto 27 */ 28 29#ifndef CCMEMORY_H 30#define CCMEMORY_H 31 32#ifdef KERNEL 33#define CC_XMALLOC(s) OSMalloc((s), CC_OSMallocTag) 34#define CC_XFREE(p, s) OSFree((p), (s), CC_OSMallocTag) 35#else /* KERNEL */ 36#include <stdlib.h> 37#include <string.h> 38 39#define CC_XMALLOC(s) malloc(s) 40#define CC_XCALLOC(c, s) calloc((c), (s)) 41#define CC_XREALLOC(p, s) realloc((p), (s)) 42#define CC_XFREE(p, s) free(p) 43#define CC_XMEMCPY(s1, s2, n) memcpy((s1), (s2), (n)) 44#define CC_XMEMCMP(s1, s2, n) memcmp((s1), (s2), (n)) 45#define CC_XMEMSET(s1, s2, n) memset((s1), (s2), (n)) 46#define CC_XZEROMEM(p, n) memset((p), 0, (n)) 47#define CC_XSTRCMP(s1, s2) strcmp((s1), (s2)) 48#define CC_XSTORE32H(x, y) do { \ 49(y)[0] = (unsigned char)(((x)>>24)&255); \ 50(y)[1] = (unsigned char)(((x)>>16)&255); \ 51(y)[2] = (unsigned char)(((x)>>8)&255); \ 52(y)[3] = (unsigned char)((x)&255); \ 53} while(0) 54#define CC_XSTORE64H(x, y) \ 55{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \ 56(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \ 57(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \ 58(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } 59 60 61 62#define CC_XQSORT(base, nelement, width, comparfunc) qsort((base), (nelement), (width), (comparfunc)) 63 64#define CC_XALIGNED(PTR,NBYTE) (!(((size_t)(PTR))%(NBYTE))) 65 66#define CC_XMIN(X,Y) (((X) < (Y)) ? (X): (Y)) 67#endif 68 69 70 71 72#endif /* CCMEMORY_H */ 73