UCommon
cpr.h File Reference

Runtime functions. More...

#include <ucommon/platform.h>
#include <unistd.h>
Include dependency graph for cpr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void cpr_freep (void **handle)
 
void * cpr_memalloc (size_t size)
 Portable memory allocation helper function.
 
void * cpr_memassign (size_t size, caddr_t address, size_t known)
 Portable memory placement helper function.
 
void cpr_memswap (void *mem1, void *mem2, size_t size)
 Portable swap code.
 
void * cpr_newp (void **handle, size_t size)
 
void cpr_runtime_error (const char *text)
 Function to handle runtime errors.
 
template<typename T >
void freep (T **handle)
 
uint32_t lsb_getlong (uint8_t *b)
 
uint16_t lsb_getshort (uint8_t *b)
 
void lsb_setlong (uint8_t *b, uint32_t v)
 
void lsb_setshort (uint8_t *b, uint16_t v)
 
uint32_t msb_getlong (uint8_t *b)
 
uint16_t msb_getshort (uint8_t *b)
 
void msb_setlong (uint8_t *b, uint32_t v)
 
void msb_setshort (uint8_t *b, uint16_t v)
 
template<typename T >
T * newp (T **handle)
 
int stricmp (const char *s1, const char *s2)
 
int strnicmp (const char *s1, const char *s2, size_t size)
 
long tzoffset (struct timezone *tz=NULL)
 

Detailed Description

Runtime functions.

This includes common runtime library functions we may need portably.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition in file cpr.h.

Function Documentation

◆ cpr_memalloc()

void * cpr_memalloc ( size_t size)

Portable memory allocation helper function.

Handles out of heap error as a runtime error.

Parameters
sizeof memory block to allocate from heap.
Returns
memory address of allocated heap space.

◆ cpr_memassign()

void * cpr_memassign ( size_t size,
caddr_t address,
size_t known )

Portable memory placement helper function.

This is used to process "placement" new operators where a new object is constructed over a pre-allocated area of memory. This handles invalid values through runtime error.

Parameters
sizeof object being constructed.
addresswhere the object is being placed.
knownsize of the location we are constructing the object in.

◆ cpr_memswap()

void cpr_memswap ( void * mem1,
void * mem2,
size_t size )

Portable swap code.

Parameters
mem1to swap.
mem2to swap.
sizeof swap area.

◆ cpr_runtime_error()

void cpr_runtime_error ( const char * text)

Function to handle runtime errors.

When using the standard C library, runtime errors are handled by a simple abort. When using the stdc++ library with stdexcept, then std::runtime_error will be thrown.

Parameters
textof runtime error.

◆ freep()

template<typename T >
void freep ( T ** handle)

Definition at line 181 of file cpr.h.

◆ newp()

template<typename T >
T * newp ( T ** handle)

Definition at line 176 of file cpr.h.