os_support.h 3.4 KB

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