symbolic4
foundation.c File Reference
#include "symbolic4.h"

Go to the source code of this file.

Functions

void * smart_alloc (uint8_t length, size_t size)
 Allocates and keeps track of memory. More...
 
void * smart_realloc (void *source, uint8_t length, size_t size)
 Resizes a pointer. More...
 
void smart_free (void *pointer)
 Frees a pointer. More...
 
void smart_free_all (void)
 Frees all pointers. More...
 
uint8_t set_error (error_domain domain, error_identifier identifier, const char *body)
 Sets current_error to the arguments provided. More...
 
void set_handle_unrecoverable_error (error_domain domain, error_identifier identifier, const char *body)
 Handles severe and unrecoverable errors. More...
 
double uintmax_max_value (void)
 
char * string_to_lower (const char *string)
 Converts a string to lowercase. More...
 
void itoa (char *buffer, uintmax_t source)
 
void dtoa (char *buffer, uint8_t length, double source)
 

Variables

error current_error
 
void ** allocated_pointers
 
bool smart_alloc_is_recording = true
 

Function Documentation

◆ dtoa()

void dtoa ( char *  buffer,
uint8_t  length,
double  source 
)

Definition at line 233 of file foundation.c.

◆ itoa()

void itoa ( char *  buffer,
uintmax_t  source 
)

Definition at line 216 of file foundation.c.

◆ set_error()

uint8_t set_error ( error_domain  domain,
error_identifier  identifier,
const char *  body 
)

Sets current_error to the arguments provided.

Parameters
[in]domain
[in]identifier
[in]body
Returns
  • Returns always RETS_ERROR

Definition at line 152 of file foundation.c.

◆ set_handle_unrecoverable_error()

void set_handle_unrecoverable_error ( error_domain  domain,
error_identifier  identifier,
const char *  body 
)

Handles severe and unrecoverable errors.

This function serves as the last resort when the program encounters exceptionally severe errors, such as a failed memory allocation, from which it can't recover itself. The

while (true);

loop may be replaced with system-specific error handling.

Warning
  • This function should only be called if everything else has failed.
Parameters
[in]domainThe error domain.
[in]identifierThe error identifier.
[in]bodyThe error body.

Definition at line 181 of file foundation.c.

◆ smart_alloc()

void* smart_alloc ( uint8_t  length,
size_t  size 
)

Allocates and keeps track of memory.

The pointer to the allocated memory is stored in the allocated_pointers array.

Precondition
  • The allocated_pointers array must be initialized with NULL, or else the loop won't work.
Warning
Parameters
[in]lengthThe length/count of the elements.
[in]sizeThe size of one element (see sizeof()).
Returns
  • A void-pointer to the allocated memory.
See also

Definition at line 59 of file foundation.c.

◆ smart_free()

void smart_free ( void *  pointer)

Frees a pointer.

This function frees a pointer and sets its corresponding entry in the allocated_pointers array to NULL.

Parameters
[in]pointerThe pointer to be freed.
See also

Definition at line 112 of file foundation.c.

◆ smart_free_all()

void smart_free_all ( void  )

Frees all pointers.

This function frees all pointers allocated with smart_alloc() by iteratively calling smart_free().

See also

Definition at line 133 of file foundation.c.

◆ smart_realloc()

void* smart_realloc ( void *  source,
uint8_t  length,
size_t  size 
)

Resizes a pointer.

The resized pointer to the allocated memory is stored in the allocated_pointers array.

Parameters
[in]sourceThe pointer to be resized.
[in]lengthThe new length/count of the elements.
[in]sizeThe size of one element (see sizeof()).
See also

Definition at line 86 of file foundation.c.

◆ string_to_lower()

char* string_to_lower ( const char *  string)

Converts a string to lowercase.

This function copies the source string and converts that copy character-wise to lowercase. The resulting string must be freed.

Parameters
[in]stringThe string to convert.
Returns
  • The new string in lowercase letters.

Definition at line 206 of file foundation.c.

◆ uintmax_max_value()

double uintmax_max_value ( void  )

Definition at line 188 of file foundation.c.

Variable Documentation

◆ allocated_pointers

void** allocated_pointers

Definition at line 29 of file foundation.c.

◆ current_error

error current_error

Definition at line 28 of file foundation.c.

◆ smart_alloc_is_recording

bool smart_alloc_is_recording = true

Definition at line 30 of file foundation.c.