Freeciv-3.3
Loading...
Searching...
No Matches
Functions
mem.c File Reference
#include <stdlib.h>
#include <string.h>
#include "fcintl.h"
#include "log.h"
#include "shared.h"
#include "mem.h"

Go to the source code of this file.

Functions

static void handle_alloc_failure (size_t size, const char *called_as, int line, const char *file)
 
voidfc_real_malloc (size_t size, const char *called_as, int line, const char *file)
 
voidfc_real_realloc (void *ptr, size_t size, const char *called_as, int line, const char *file)
 
voidfc_real_calloc (size_t nelem, size_t elsize, const char *called_as, int line, const char *file)
 
charreal_fc_strdup (const char *str, const char *called_as, int line, const char *file)
 

Function Documentation

◆ fc_real_calloc()

void * fc_real_calloc ( size_t  nelem,
size_t  elsize,
const char called_as,
int  line,
const char file 
)

Function used by fc_calloc() macro, calloc() replacement No need to check return value.

I'm pretty sure only the product of nelem and elsize can ever matter here, and not their individual values. (As a matter of C.) Except this function doesn't support calloc-ing more memory than can be expressing using a single size_t, but that's not likely to be a problem.

Definition at line 132 of file mem.c.

◆ fc_real_malloc()

void * fc_real_malloc ( size_t  size,
const char called_as,
int  line,
const char file 
)

Function used by fc_malloc() macro, malloc() replacement

There's no need for the caller to check return value; this function will always return a valid pointer (even for a 0-byte malloc).

Definition at line 73 of file mem.c.

Referenced by fc_real_calloc(), fc_real_realloc(), and real_fc_strdup().

◆ fc_real_realloc()

void * fc_real_realloc ( void ptr,
size_t  size,
const char called_as,
int  line,
const char file 
)

Function used by fc_realloc() macro, realloc() replacement No need to check return value.

Definition at line 101 of file mem.c.

◆ handle_alloc_failure()

static void handle_alloc_failure ( size_t  size,
const char called_as,
int  line,
const char file 
)
static

Do whatever we should do when fc_malloc() fails. At the moment this just prints a log message and calls exit(EXIT_FAILURE)

Definition at line 38 of file mem.c.

Referenced by fc_real_malloc(), and fc_real_realloc().

◆ real_fc_strdup()

char * real_fc_strdup ( const char str,
const char called_as,
int  line,
const char file 
)

Function used by fc_strdup() macro, strdup() replacement No need to check return value.

Definition at line 148 of file mem.c.