Defines | Functions

eurephia_nullsafe.c File Reference

standard C string functions, which is made NULL safe by checking if input value is NULL before performing the action. More...

#include <stdio.h>
#include <stdlib.h>
#include <eurephia_context.h>
#include <eurephia_log.h>
Include dependency graph for eurephia_nullsafe.c:

Go to the source code of this file.

Functions

void * _malloc_nullsafe (eurephiaCTX *ctx, size_t sz, const char *file, int line)
void _free_nullsafe (eurephiaCTX *ctx, void *ptr, const char *file, int line)

Detailed Description

standard C string functions, which is made NULL safe by checking if input value is NULL before performing the action.

Author:
David Sommerseth <dazo@users.sourceforge.net>
Date:
2009-09-07

Definition in file eurephia_nullsafe.c.


Function Documentation

void _free_nullsafe ( eurephiaCTX ctx,
void *  ptr,
const char *  file,
int  line 
) [inline]

Internal function for freeing memory. Also does some logging of the freeing if debug level enabled and log level high enough. Should be called via the free_nullsafe() macro.

Parameters:
ctx eurephiaCTX (for logging only)
ptr Pointer to the memory region to be freed
file debug info, which file is doing this call
line debug info, which line in the file

< Messages intended when debugging. Only for log level > 10

Definition at line 97 of file eurephia_nullsafe.c.

Here is the call graph for this function:

void* _malloc_nullsafe ( eurephiaCTX ctx,
size_t  sz,
const char *  file,
int  line 
)

Internal function, should be called via the malloc_nullsafe() macro. This replaces the use of malloc() and memset(). This function uses calloc internally, which results in the memory region being zero'd by the kernel on memory allocation.

Parameters:
ctx eurephiaCTX, used for logging
sz size of the memory region being allocated
file debug info, which file is doing this call
line debug info, which line in the file
Returns:
Returns a void pointer to the memory region on success, otherwise NULL

< Alias for LOG_FATAL

< Operation failed and cannot continue. Log level always < 2

< Messages intended when debugging. Only for log level > 10

Definition at line 60 of file eurephia_nullsafe.c.

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines