Memory helpers

Overview

Implementation of API to use memory-related functions in a convenient way

Copyright (C) 2004-2022 OKTET Labs Ltd. More…

// global functions

void* tapi_malloc(size_t size);
void* tapi_malloc_or_null(size_t size);
void* tapi_calloc(size_t nmemb, size_t size);
void* tapi_realloc(void* ptr, size_t size);
void* tapi_memdup(const void* ptr, size_t size);
char* tapi_strdup(const char* s);
char* tapi_strndup(const char* s, size_t size);

Detailed Documentation

Implementation of API to use memory-related functions in a convenient way

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Global Functions

void* tapi_malloc(size_t size)

malloc() wrapper which performs allocation status check internally

Parameters:

size

Size of memory to allocate

Returns:

Pointer to an allocated memory (never returns NULL)

void* tapi_malloc_or_null(size_t size)

malloc() wrapper which performs allocation status check internally.

Parameters:

size

Size of memory to allocate.

Returns:

Pointer to an allocated memory or NULL if size is 0 and never NULL othewise.

void* tapi_calloc(size_t nmemb, size_t size)

calloc() wrapper which performs allocation status check internally

Parameters:

nmemb

Number of memory elements to allocate

size

Size of an element

Returns:

Pointer to an allocated memory (never returns NULL)

void* tapi_realloc(void* ptr, size_t size)

realloc() wrapper which performs allocation status check internally

Parameters:

ptr

Pointer to a memory block to re-allocate

size

New size for a memory block to re-allocate

Returns:

Pointer to re-allocated memory (never returns NULL)

void* tapi_memdup(const void* ptr, size_t size)

malloc() + memcpy() wrapper designed to simplify memory copying

Parameters:

ptr

Source memory pointer

size

Size of the memory block pointed by ptr

Returns:

Pointer to a memory block copy (never returns NULL)

char* tapi_strdup(const char* s)

strdup() wrapper which performs duplication status check internally

Parameters:

s

Pointer to a source string to be duplicated

Returns:

Pointer to a string copy (never returns NULL)

char* tapi_strndup(const char* s, size_t size)

strndup() wrapper which performs duplication status check internally

Parameters:

s

Pointer to a source string to be duplicated

size

Counts of bytes to copy from a source string

Returns:

Pointer to a string copy (never returns NULL)