4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 static const AvahiAllocator *allocator = NULL;
35 void *avahi_malloc(size_t size) {
43 assert(allocator->malloc);
44 return allocator->malloc(size);
47 void *avahi_malloc0(size_t size) {
54 return calloc(1, size);
56 if (allocator->calloc)
57 return allocator->calloc(1, size);
59 assert(allocator->malloc);
60 if ((p = allocator->malloc(size)))
66 void avahi_free(void *p) {
76 assert(allocator->free);
80 void *avahi_realloc(void *p, size_t size) {
83 return realloc(p, size);
85 assert(allocator->realloc);
86 return allocator->realloc(p, size);
89 char *avahi_strdup(const char *s) {
97 if (!(r = avahi_malloc(size+1)))
100 memcpy(r, s, size+1);
104 char *avahi_strndup(const char *s, size_t max) {
116 if (!(r = avahi_malloc(size+1)))
124 /* Change the allocator */
125 void avahi_set_allocator(const AvahiAllocator *a) {
129 char *avahi_strdup_vprintf(const char *fmt, va_list ap) {
135 if (!(buf = avahi_malloc(len)))
142 n = vsnprintf(buf, len, fmt, ap);
144 if (n >= 0 && n < (int) len)
152 if (!(nbuf = avahi_realloc(buf, len))) {
161 char *avahi_strdup_printf(const char *fmt, ... ) {
166 s = avahi_strdup_vprintf(fmt, ap);