xmalloc.h

Go to the documentation of this file.
00001 #ifndef foomemoryhfoo
00002 #define foomemoryhfoo
00003 
00004 /***
00005   This file is part of PulseAudio.
00006 
00007   Copyright 2004-2006 Lennart Poettering
00008 
00009   PulseAudio is free software; you can redistribute it and/or modify
00010   it under the terms of the GNU Lesser General Public License as published
00011   by the Free Software Foundation; either version 2 of the License,
00012   or (at your option) any later version.
00013 
00014   PulseAudio is distributed in the hope that it will be useful, but
00015   WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017   General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public License
00020   along with PulseAudio; if not, write to the Free Software
00021   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022   USA.
00023 ***/
00024 
00025 #include <sys/types.h>
00026 #include <stdlib.h>
00027 #include <limits.h>
00028 #include <assert.h>
00029 
00030 #include <pulse/cdecl.h>
00031 #include <pulse/gccmacro.h>
00032 
00037 PA_C_DECL_BEGIN
00038 
00040 void* pa_xmalloc(size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(1);
00041 
00043 void *pa_xmalloc0(size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(1);
00044 
00046 void *pa_xrealloc(void *ptr, size_t size) PA_GCC_ALLOC_SIZE(2);
00047 
00049 void pa_xfree(void *p);
00050 
00052 char *pa_xstrdup(const char *s) PA_GCC_MALLOC;
00053 
00055 char *pa_xstrndup(const char *s, size_t l) PA_GCC_MALLOC;
00056 
00058 void* pa_xmemdup(const void *p, size_t l) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE(2);
00059 
00061 static void* _pa_xnew_internal(size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(1,2);
00062 
00063 static inline void* _pa_xnew_internal(size_t n, size_t k) {
00064     assert(n < INT_MAX/k);
00065     return pa_xmalloc(n*k);
00066 }
00067 
00069 #define pa_xnew(type, n) ((type*) _pa_xnew_internal((n), sizeof(type)))
00070 
00072 static void* _pa_xnew0_internal(size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(1,2);
00073 
00074 static inline void* _pa_xnew0_internal(size_t n, size_t k) {
00075     assert(n < INT_MAX/k);
00076     return pa_xmalloc0(n*k);
00077 }
00078 
00080 #define pa_xnew0(type, n) ((type*) _pa_xnew0_internal((n), sizeof(type)))
00081 
00083 static void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) PA_GCC_MALLOC PA_GCC_ALLOC_SIZE2(2,3);
00084 
00085 static inline void* _pa_xnewdup_internal(const void *p, size_t n, size_t k) {
00086     assert(n < INT_MAX/k);
00087     return pa_xmemdup(p, n*k);
00088 }
00089 
00091 #define pa_xnewdup(type, p, n) ((type*) _pa_xnewdup_internal((p), (n), sizeof(type)))
00092 
00093 PA_C_DECL_END
00094 
00095 #endif

Generated on Tue Sep 16 10:58:58 2008 for PulseAudio by  doxygen 1.5.4