michael@0: /* Copyright (C) 2007 Jean-Marc Valin michael@0: michael@0: File: os_support.h michael@0: This is the (tiny) OS abstraction layer. Aside from math.h, this is the michael@0: only place where system headers are allowed. michael@0: michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions are michael@0: met: michael@0: michael@0: 1. Redistributions of source code must retain the above copyright notice, michael@0: this list of conditions and the following disclaimer. michael@0: michael@0: 2. Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR michael@0: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES michael@0: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE michael@0: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, michael@0: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES michael@0: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR michael@0: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, michael@0: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN michael@0: ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE michael@0: POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifndef OS_SUPPORT_H michael@0: #define OS_SUPPORT_H michael@0: michael@0: #ifdef CUSTOM_SUPPORT michael@0: # include "custom_support.h" michael@0: #endif michael@0: michael@0: #include "opus_types.h" michael@0: #include "opus_defines.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: /** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */ michael@0: #ifndef OVERRIDE_OPUS_ALLOC michael@0: static OPUS_INLINE void *opus_alloc (size_t size) michael@0: { michael@0: return malloc(size); michael@0: } michael@0: #endif michael@0: michael@0: /** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */ michael@0: #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH michael@0: static OPUS_INLINE void *opus_alloc_scratch (size_t size) michael@0: { michael@0: /* Scratch space doesn't need to be cleared */ michael@0: return opus_alloc(size); michael@0: } michael@0: #endif michael@0: michael@0: /** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */ michael@0: #ifndef OVERRIDE_OPUS_FREE michael@0: static OPUS_INLINE void opus_free (void *ptr) michael@0: { michael@0: free(ptr); michael@0: } michael@0: #endif michael@0: michael@0: /** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */ michael@0: #ifndef OVERRIDE_OPUS_COPY michael@0: #define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) michael@0: #endif michael@0: michael@0: /** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term michael@0: provides compile-time type checking */ michael@0: #ifndef OVERRIDE_OPUS_MOVE michael@0: #define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) michael@0: #endif michael@0: michael@0: /** Set n elements of dst to zero, starting at address s */ michael@0: #ifndef OVERRIDE_OPUS_CLEAR michael@0: #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst)))) michael@0: #endif michael@0: michael@0: /*#ifdef __GNUC__ michael@0: #pragma GCC poison printf sprintf michael@0: #pragma GCC poison malloc free realloc calloc michael@0: #endif*/ michael@0: michael@0: #endif /* OS_SUPPORT_H */ michael@0: