avahi  0.7
malloc.h File Reference

Memory allocation. More...

#include <sys/types.h>
#include <stdarg.h>
#include <limits.h>
#include <assert.h>
#include <avahi-common/cdecl.h>
#include <avahi-common/gccmacro.h>

Go to the source code of this file.

Data Structures

struct  AvahiAllocator
 Wraps allocator functions. More...
 

Macros

#define avahi_new(type, n)   ((type*) avahi_new_internal((n), sizeof(type)))
 Allocate n new structures of the specified type. More...
 
#define avahi_new0(type, n)   ((type*) avahi_new0_internal((n), sizeof(type)))
 Same as avahi_new() but set the memory to zero. More...
 

Typedefs

typedef struct AvahiAllocator AvahiAllocator
 Wraps allocator functions. More...
 

Functions

void * avahi_malloc (size_t size) AVAHI_GCC_ALLOC_SIZE(1)
 Allocate some memory, just like the libc malloc() More...
 
void * avahi_malloc0 (size_t size) AVAHI_GCC_ALLOC_SIZE(1)
 Similar to avahi_malloc() but set the memory to zero. More...
 
void avahi_free (void *p)
 Free some memory. More...
 
void * avahi_realloc (void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2)
 Similar to libc's realloc() More...
 
return avahi_malloc (n *k)
 
return avahi_malloc0 (n *k)
 
char * avahi_strdup (const char *s)
 Just like libc's strdup() More...
 
char * avahi_strndup (const char *s, size_t l)
 Just like libc's strndup() More...
 
void * avahi_memdup (const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2)
 Duplicate the given memory block into a new one allocated with avahi_malloc() More...
 
void avahi_set_allocator (const AvahiAllocator *a)
 Change the allocator. More...
 
char * avahi_strdup_printf (const char *fmt,...) AVAHI_GCC_PRINTF_ATTR12
 Like sprintf() but store the result in a freshly allocated buffer. More...
 

Variables

static void size_t k
 

Detailed Description

Memory allocation.

Definition in file malloc.h.

Macro Definition Documentation

◆ avahi_new

#define avahi_new (   type,
 
)    ((type*) avahi_new_internal((n), sizeof(type)))

Allocate n new structures of the specified type.

Definition at line 54 of file malloc.h.

◆ avahi_new0

#define avahi_new0 (   type,
 
)    ((type*) avahi_new0_internal((n), sizeof(type)))

Same as avahi_new() but set the memory to zero.

Definition at line 63 of file malloc.h.

Typedef Documentation

◆ AvahiAllocator

Wraps allocator functions.

Function Documentation

◆ avahi_free()

void avahi_free ( void *  p)

Free some memory.

Examples:
client-browse-services.c, and client-publish-service.c.

◆ avahi_malloc() [1/2]

void* avahi_malloc ( size_t  size)

Allocate some memory, just like the libc malloc()

◆ avahi_malloc() [2/2]

return avahi_malloc ( n *  k)

◆ avahi_malloc0() [1/2]

void* avahi_malloc0 ( size_t  size)

Similar to avahi_malloc() but set the memory to zero.

◆ avahi_malloc0() [2/2]

return avahi_malloc0 ( n *  k)

◆ avahi_memdup()

void* avahi_memdup ( const void *  s,
size_t  l 
)

Duplicate the given memory block into a new one allocated with avahi_malloc()

◆ avahi_realloc()

void* avahi_realloc ( void *  p,
size_t  size 
)

Similar to libc's realloc()

◆ avahi_set_allocator()

void avahi_set_allocator ( const AvahiAllocator a)

Change the allocator.

May be NULL to return to default (libc) allocators. The structure is not copied!

Examples:
glib-integration.c.

◆ avahi_strdup()

char* avahi_strdup ( const char *  s)

Just like libc's strdup()

Examples:
client-publish-service.c.

◆ avahi_strdup_printf()

char* avahi_strdup_printf ( const char *  fmt,
  ... 
)

Like sprintf() but store the result in a freshly allocated buffer.

Free this with avahi_free()

◆ avahi_strndup()

char* avahi_strndup ( const char *  s,
size_t  l 
)

Just like libc's strndup()

Variable Documentation

◆ k

static void size_t k
Initial value:
{
assert(n < INT_MAX/k)
static void size_t k
Definition: malloc.h:48

Definition at line 48 of file malloc.h.