Blame libcelt/os_support.h

Packit 664db3
/* Copyright (C) 2007 Jean-Marc Valin
Packit 664db3
      
Packit 664db3
   File: os_support.h
Packit 664db3
   This is the (tiny) OS abstraction layer. Aside from math.h, this is the
Packit 664db3
   only place where system headers are allowed.
Packit 664db3
Packit 664db3
   Redistribution and use in source and binary forms, with or without
Packit 664db3
   modification, are permitted provided that the following conditions are
Packit 664db3
   met:
Packit 664db3
Packit 664db3
   1. Redistributions of source code must retain the above copyright notice,
Packit 664db3
   this list of conditions and the following disclaimer.
Packit 664db3
Packit 664db3
   2. Redistributions in binary form must reproduce the above copyright
Packit 664db3
   notice, this list of conditions and the following disclaimer in the
Packit 664db3
   documentation and/or other materials provided with the distribution.
Packit 664db3
Packit 664db3
   3. The name of the author may not be used to endorse or promote products
Packit 664db3
   derived from this software without specific prior written permission.
Packit 664db3
Packit 664db3
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit 664db3
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit 664db3
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 664db3
   DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
Packit 664db3
   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Packit 664db3
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 664db3
   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 664db3
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Packit 664db3
   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
Packit 664db3
   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit 664db3
   POSSIBILITY OF SUCH DAMAGE.
Packit 664db3
*/
Packit 664db3
Packit 664db3
#ifndef OS_SUPPORT_H
Packit 664db3
#define OS_SUPPORT_H
Packit 664db3
Packit 664db3
#ifdef CUSTOM_SUPPORT
Packit 664db3
#  include "custom_support.h"
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#include <string.h>
Packit 664db3
#include <stdio.h>
Packit 664db3
#include <stdlib.h>
Packit 664db3
Packit 664db3
/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_free 
Packit 664db3
    NOTE: celt_alloc needs to CLEAR THE MEMORY */
Packit 664db3
#ifndef OVERRIDE_CELT_ALLOC
Packit 664db3
static inline void *celt_alloc (int size)
Packit 664db3
{
Packit 664db3
   /* WARNING: this is not equivalent to malloc(). If you want to use malloc() 
Packit 664db3
      or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
Packit 664db3
      you will experience strange bugs */
Packit 664db3
   return calloc(size,1);
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Same as celt_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
Packit 664db3
#ifndef OVERRIDE_CELT_ALLOC_SCRATCH
Packit 664db3
static inline void *celt_alloc_scratch (int size)
Packit 664db3
{
Packit 664db3
   /* Scratch space doesn't need to be cleared */
Packit 664db3
   return calloc(size,1);
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, celt_alloc and celt_free */
Packit 664db3
#ifndef OVERRIDE_CELT_REALLOC
Packit 664db3
static inline void *celt_realloc (void *ptr, int size)
Packit 664db3
{
Packit 664db3
   return realloc(ptr, size);
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_alloc */
Packit 664db3
#ifndef OVERRIDE_CELT_FREE
Packit 664db3
static inline void celt_free (void *ptr)
Packit 664db3
{
Packit 664db3
   free(ptr);
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Same as celt_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
Packit 664db3
#ifndef OVERRIDE_CELT_FREE_SCRATCH
Packit 664db3
static inline void celt_free_scratch (void *ptr)
Packit 664db3
{
Packit 664db3
   free(ptr);
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking  */
Packit 664db3
#ifndef OVERRIDE_CELT_COPY
Packit 664db3
#define CELT_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term 
Packit 664db3
    provides compile-time type checking */
Packit 664db3
#ifndef OVERRIDE_CELT_MOVE
Packit 664db3
#define CELT_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
Packit 664db3
#endif
Packit 664db3
Packit 664db3
/** Set n bytes of memory to value of c, starting at address s */
Packit 664db3
#ifndef OVERRIDE_CELT_MEMSET
Packit 664db3
#define CELT_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
Packit 664db3
#endif
Packit 664db3
Packit 664db3
Packit 664db3
#ifndef OVERRIDE_CELT_FATAL
Packit 664db3
static inline void _celt_fatal(const char *str, const char *file, int line)
Packit 664db3
{
Packit 664db3
   fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
Packit 664db3
   abort();
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#ifndef OVERRIDE_CELT_WARNING
Packit 664db3
static inline void celt_warning(const char *str)
Packit 664db3
{
Packit 664db3
#ifndef DISABLE_WARNINGS
Packit 664db3
   fprintf (stderr, "warning: %s\n", str);
Packit 664db3
#endif
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#ifndef OVERRIDE_CELT_WARNING_INT
Packit 664db3
static inline void celt_warning_int(const char *str, int val)
Packit 664db3
{
Packit 664db3
#ifndef DISABLE_WARNINGS
Packit 664db3
   fprintf (stderr, "warning: %s %d\n", str, val);
Packit 664db3
#endif
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
#ifndef OVERRIDE_CELT_NOTIFY
Packit 664db3
static inline void celt_notify(const char *str)
Packit 664db3
{
Packit 664db3
#ifndef DISABLE_NOTIFICATIONS
Packit 664db3
   fprintf (stderr, "notification: %s\n", str);
Packit 664db3
#endif
Packit 664db3
}
Packit 664db3
#endif
Packit 664db3
Packit 664db3
Packit 664db3
Packit 664db3
/*#ifdef __GNUC__
Packit 664db3
#pragma GCC poison printf sprintf
Packit 664db3
#pragma GCC poison malloc free realloc calloc
Packit 664db3
#endif*/
Packit 664db3
Packit 664db3
#endif /* OS_SUPPORT_H */
Packit 664db3