|
avahi 0.6.30
|
00001 #ifndef foomallochfoo 00002 #define foomallochfoo 00003 00004 /*** 00005 This file is part of avahi. 00006 00007 avahi is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU Lesser General Public License as 00009 published by the Free Software Foundation; either version 2.1 of the 00010 License, or (at your option) any later version. 00011 00012 avahi is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00014 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 00015 Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with avahi; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00020 USA. 00021 ***/ 00022 00025 #include <sys/types.h> 00026 #include <stdarg.h> 00027 #include <limits.h> 00028 #include <assert.h> 00029 00030 #include <avahi-common/cdecl.h> 00031 #include <avahi-common/gccmacro.h> 00032 00033 AVAHI_C_DECL_BEGIN 00034 00036 void *avahi_malloc(size_t size) AVAHI_GCC_ALLOC_SIZE(1); 00037 00039 void *avahi_malloc0(size_t size) AVAHI_GCC_ALLOC_SIZE(1); 00040 00042 void avahi_free(void *p); 00043 00045 void *avahi_realloc(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2); 00046 00048 static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) { 00049 assert(n < INT_MAX/k); 00050 return avahi_malloc(n*k); 00051 } 00052 00054 #define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type))) 00055 00057 static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) { 00058 assert(n < INT_MAX/k); 00059 return avahi_malloc0(n*k); 00060 } 00061 00063 #define avahi_new0(type, n) ((type*) avahi_new0_internal((n), sizeof(type))) 00064 00066 char *avahi_strdup(const char *s); 00067 00069 char *avahi_strndup(const char *s, size_t l); 00070 00072 void *avahi_memdup(const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2); 00073 00075 typedef struct AvahiAllocator { 00076 void* (*malloc)(size_t size) AVAHI_GCC_ALLOC_SIZE(1); 00077 void (*free)(void *p); 00078 void* (*realloc)(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2); 00079 void* (*calloc)(size_t nmemb, size_t size) AVAHI_GCC_ALLOC_SIZE2(1,2); 00080 } AvahiAllocator; 00081 00084 void avahi_set_allocator(const AvahiAllocator *a); 00085 00087 char *avahi_strdup_printf(const char *fmt, ... ) AVAHI_GCC_PRINTF_ATTR12; 00088 00091 char *avahi_strdup_vprintf(const char *fmt, va_list ap); 00094 AVAHI_C_DECL_END 00095 00096 #endif