Back to index

avfs  1.0.1
Defines | Functions | Variables
ne_alloc.c File Reference
#include "config.h"
#include "ne_alloc.h"

Go to the source code of this file.

Defines

#define DO_MALLOC(ptr, len)

Functions

void ne_oom_callback (void(*callback)(void))
void * ne_malloc (size_t len)
void * ne_calloc (size_t len)
void * ne_realloc (void *ptr, size_t len)
char * ne_strdup (const char *s)
char * ne_strndup (const char *s, size_t n)

Variables

static void(* oom )(void)

Define Documentation

#define DO_MALLOC (   ptr,
  len 
)
Value:
do {          \
    ptr = malloc(len);                           \
    if (!ptr) {                                  \
       if (oom != NULL)                   \
           oom();                         \
       abort();                           \
    }                                     \
} while(0);

Definition at line 36 of file ne_alloc.c.


Function Documentation

void* ne_calloc ( size_t  len)

Definition at line 57 of file ne_alloc.c.

{
    void *ptr;
    DO_MALLOC(ptr, len);
    return memset(ptr, 0, len);
}
void* ne_malloc ( size_t  len)

Definition at line 50 of file ne_alloc.c.

{
    void *ptr;
    DO_MALLOC(ptr, len);
    return ptr;
}
void ne_oom_callback ( void(*)(void)  callback)

Definition at line 45 of file ne_alloc.c.

{
    oom = callback;
}
void* ne_realloc ( void *  ptr,
size_t  len 
)

Definition at line 64 of file ne_alloc.c.

{
    void *ret = realloc(ptr, len);
    if (!ret) {
       if (oom)
           oom();
       abort();
    }
    return ret;
}
char* ne_strdup ( const char *  s)

Definition at line 75 of file ne_alloc.c.

{
    char *ret;
    DO_MALLOC(ret, strlen(s) + 1);
    return strcpy(ret, s);
}
char* ne_strndup ( const char *  s,
size_t  n 
)

Definition at line 82 of file ne_alloc.c.

{
    char *new;
    DO_MALLOC(new, n);
    new[n] = '\0';
    memcpy(new, s, n);
    return new;
}

Variable Documentation

void(* oom)(void) [static]

Definition at line 34 of file ne_alloc.c.