]> git.meshlink.io Git - catta/blob - avahi-common/malloc.h
* drop glib from avahi-common
[catta] / avahi-common / malloc.h
1 #ifndef foomallochfoo
2 #define foomallochfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of avahi.
8  
9   avahi is free software; you can redistribute it and/or modify it
10   under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13  
14   avahi is distributed in the hope that it will be useful, but WITHOUT
15   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17   Public License for more details.
18  
19   You should have received a copy of the GNU Lesser General Public
20   License along with avahi; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 #include <sys/types.h>
26 #include <stdarg.h>
27
28 /** Allocate some memory, just like the libc malloc() */
29 void *avahi_malloc(size_t size);
30
31 /** Similar to avahi_malloc() but set the memory to zero */
32 void *avahi_malloc0(size_t size);
33
34 /** Free some memory */
35 void avahi_free(void *p);
36
37 /** Similar to libc's realloc() */
38 void *avahi_realloc(void *p, size_t size);
39
40 /** Allocate n new structures of the specified type. */
41 #define avahi_new(type, n) (type*) avahi_malloc(n*sizeof(type))
42
43 /** Same as avahi_new() but set the memory to zero */
44 #define avahi_new0(type, n) (type*) avahi_malloc0(n*sizeof(type))
45
46 /* Just like libc's strdup() */
47 char *avahi_strdup(const char *s);
48
49 /* Just like libc's strndup() */
50 char *avahi_strndup(const char *s, size_t l); 
51
52 /** Wraps allocator functions */
53 typedef struct AvahiAllocator AvahiAllocator;
54 struct AvahiAllocator {
55     void* (*malloc)(size_t size);     
56     void (*free)(void *p);           
57     void* (*realloc)(void *p, size_t size);
58     void* (*calloc)(size_t nmemb, size_t size);   /**< May be NULL */
59 };
60
61 /* Change the allocator. May be NULL to return to default (libc)
62  * allocators. The structure is not copied! */
63 void avahi_set_allocator(const AvahiAllocator *a);
64
65
66 char *avahi_strdup_vprintf(const char *fmt, va_list ap);
67
68 #ifdef __GNUC__
69 char *avahi_strdup_printf(const char *fmt, ... )  __attribute__ ((format(printf, 1, 2)));
70 #else
71 char *avahi_strdup_printf(const char *fmt, ... );
72 #endif
73
74
75 #endif