os_support.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <string.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. /** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */
  34. #ifndef OVERRIDE_OPUS_ALLOC
  35. static inline void *opus_alloc (size_t size)
  36. {
  37. return malloc(size);
  38. }
  39. #endif
  40. /** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
  41. #ifndef OVERRIDE_OPUS_ALLOC_SCRATCH
  42. static inline void *opus_alloc_scratch (size_t size)
  43. {
  44. /* Scratch space doesn't need to be cleared */
  45. return opus_alloc(size);
  46. }
  47. #endif
  48. /** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */
  49. #ifndef OVERRIDE_OPUS_FREE
  50. static inline void opus_free (void *ptr)
  51. {
  52. free(ptr);
  53. }
  54. #endif
  55. /** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */
  56. #ifndef OVERRIDE_OPUS_COPY
  57. #define OPUS_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
  58. #endif
  59. /** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term
  60. provides compile-time type checking */
  61. #ifndef OVERRIDE_OPUS_MOVE
  62. #define OPUS_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
  63. #endif
  64. /** Set n elements of dst to zero, starting at address s */
  65. #ifndef OVERRIDE_OPUS_CLEAR
  66. #define OPUS_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst))))
  67. #endif
  68. /*#ifdef __GNUC__
  69. #pragma GCC poison printf sprintf
  70. #pragma GCC poison malloc free realloc calloc
  71. #endif*/
  72. #endif /* OS_SUPPORT_H */