~ubuntu-branches/ubuntu/raring/mumble/raring

« back to all changes in this revision

Viewing changes to celt-0.11.0-src/libcelt/os_support.h

  • Committer: Bazaar Package Importer
  • Author(s): Thorvald Natvig, Patrick Matthäi, Thorvald Natvig
  • Date: 2011-02-19 22:58:58 UTC
  • mfrom: (9.1.15 sid)
  • Revision ID: james.westby@ubuntu.com-20110219225858-0xlftrf4z1z4jt9e
Tags: 1.2.3-1
[ Patrick Matthäi ]
* Do not build with non existant libpulse-dev on hurd-i386.

[ Thorvald Natvig ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2007 Jean-Marc Valin
 
2
      
 
3
   File: os_support.h
 
4
   This is the (tiny) OS abstraction layer. Aside from math.h, this is the
 
5
   only place where system headers are allowed.
 
6
 
 
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
 
 
11
   1. Redistributions of source code must retain the above copyright notice,
 
12
   this list of conditions and the following disclaimer.
 
13
 
 
14
   2. Redistributions in binary form must reproduce the above copyright
 
15
   notice, this list of conditions and the following disclaimer in the
 
16
   documentation and/or other materials provided with the distribution.
 
17
 
 
18
   3. The name of the author may not be used to endorse or promote products
 
19
   derived from this software without specific prior written permission.
 
20
 
 
21
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 
22
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
23
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
24
   DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 
25
   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
26
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
27
   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
28
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
29
   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
30
   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
31
   POSSIBILITY OF SUCH DAMAGE.
 
32
*/
 
33
 
 
34
#ifndef OS_SUPPORT_H
 
35
#define OS_SUPPORT_H
 
36
 
 
37
#ifdef CUSTOM_SUPPORT
 
38
#  include "custom_support.h"
 
39
#endif
 
40
 
 
41
#include <string.h>
 
42
#include <stdio.h>
 
43
#include <stdlib.h>
 
44
 
 
45
/** CELT wrapper for calloc(). To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_free 
 
46
    NOTE: celt_alloc needs to CLEAR THE MEMORY */
 
47
#ifndef OVERRIDE_CELT_ALLOC
 
48
static inline void *celt_alloc (int size)
 
49
{
 
50
   /* WARNING: this is not equivalent to malloc(). If you want to use malloc() 
 
51
      or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
 
52
      you will experience strange bugs */
 
53
   return calloc(size,1);
 
54
}
 
55
#endif
 
56
 
 
57
/** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
 
58
#ifndef OVERRIDE_CELT_ALLOC_SCRATCH
 
59
static inline void *celt_alloc_scratch (int size)
 
60
{
 
61
   /* Scratch space doesn't need to be cleared */
 
62
   return calloc(size,1);
 
63
}
 
64
#endif
 
65
 
 
66
/** CELT wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_alloc */
 
67
#ifndef OVERRIDE_CELT_FREE
 
68
static inline void celt_free (void *ptr)
 
69
{
 
70
   free(ptr);
 
71
}
 
72
#endif
 
73
 
 
74
/** Same as celt_free(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
 
75
#ifndef OVERRIDE_CELT_FREE_SCRATCH
 
76
static inline void celt_free_scratch (void *ptr)
 
77
{
 
78
   free(ptr);
 
79
}
 
80
#endif
 
81
 
 
82
/** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking  */
 
83
#ifndef OVERRIDE_CELT_COPY
 
84
#define CELT_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
 
85
#endif
 
86
 
 
87
/** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term 
 
88
    provides compile-time type checking */
 
89
#ifndef OVERRIDE_CELT_MOVE
 
90
#define CELT_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
 
91
#endif
 
92
 
 
93
/** Set n bytes of memory to value of c, starting at address s */
 
94
#ifndef OVERRIDE_CELT_MEMSET
 
95
#define CELT_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
 
96
#endif
 
97
 
 
98
/*#ifdef __GNUC__
 
99
#pragma GCC poison printf sprintf
 
100
#pragma GCC poison malloc free realloc calloc
 
101
#endif*/
 
102
 
 
103
#endif /* OS_SUPPORT_H */
 
104