os_support.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright (C) 2007 Jean-Marc Valin
  2. File: os_support.h
  3. This is the (tiny) OS abstraction layer. Aside from math.h, this is the
  4. only place where system headers are allowed.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are
  7. met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  17. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  21. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef OS_SUPPORT_H
  26. #define OS_SUPPORT_H
  27. #ifdef CUSTOM_SUPPORT
  28. # include "custom_support.h"
  29. #endif
  30. #include "opus_types.h"
  31. #include "opus_defines.h"
  32. #include <string.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. /** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */
  36. #ifndef OVERRIDE_OPUS_ALLOC
  37. static OPUS_INLINE void *opus_alloc (size_t size)
  38. {
  39. return malloc(size);
  40. }
  41. #endif
  42. /** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
  43. #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH
  44. static OPUS_INLINE void *opus_alloc_scratch (size_t size)
  45. {
  46. /* Scratch space doesn't need to be cleared */
  47. return opus_alloc(size);
  48. }
  49. #endif
  50. /** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */
  51. #ifndef OVERRIDE_OPUS_FREE
  52. static OPUS_INLINE void opus_free (void *ptr)
  53. {
  54. free(ptr);
  55. }
  56. #endif
  57. /** Copy n elements from src to dst. The 0* term provides compile-time type checking */
  58. #ifndef OVERRIDE_OPUS_COPY
  59. #define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
  60. #endif
  61. /** Copy n elements from src to dst, allowing overlapping regions. The 0* term
  62. provides compile-time type checking */
  63. #ifndef OVERRIDE_OPUS_MOVE
  64. #define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
  65. #endif
  66. /** Set n elements of dst to zero */
  67. #ifndef OVERRIDE_OPUS_CLEAR
  68. #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst))))
  69. #endif
  70. /*#ifdef __GNUC__
  71. #pragma GCC poison printf sprintf
  72. #pragma GCC poison malloc free realloc calloc
  73. #endif*/
  74. #endif /* OS_SUPPORT_H */