poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
util.h File Reference

generic utility functions More...

#include <poser/decl.h>
#include <stddef.h>

Go to the source code of this file.

Functions

void * PSC_malloc (size_t size)
 Allocate memory.
 
void * PSC_realloc (void *ptr, size_t size)
 Re-allocate memory.
 
char * PSC_copystr (const char *src)
 Copy a string.
 
char * PSC_lowerstr (const char *src)
 Lowercase a string.
 
char * PSC_joinstr (const char *delim, char **strings)
 Join multiple strings.
 

Detailed Description

generic utility functions

Function Documentation

◆ PSC_copystr()

char * PSC_copystr ( const char *  src)

Copy a string.

This is similar to strdup(), but uses PSC_malloc() internally.

Parameters
srcthe string to copy
Returns
a newly allocated copy of the string

◆ PSC_joinstr()

char * PSC_joinstr ( const char *  delim,
char **  strings 
)

Join multiple strings.

This joins an array of strings into a new string, putting a delimeter between all the elements.

Parameters
delimthe delimeter
stringsthe strings to join, array must end with a NULL pointer
Returns
a newly allocated joined string

◆ PSC_lowerstr()

char * PSC_lowerstr ( const char *  src)

Lowercase a string.

This creates a copy of the string in all lowercase.

Parameters
srcthe string to copy
Returns
a newly allocated lowercased string

◆ PSC_malloc()

void * PSC_malloc ( size_t  size)

Allocate memory.

This is a wrapper around malloc() that ensures only valid pointers are returned. In case of an allocation error, PSC_Service_panic() is called.

Parameters
sizesize of the memory to allocate
Returns
the newly allocated memory

◆ PSC_realloc()

void * PSC_realloc ( void *  ptr,
size_t  size 
)

Re-allocate memory.

This is a wrapper around realloc() that ensures only valid pointers are returned. In case of an allocation error, PSC_Service_panic() is called.

Parameters
ptrthe previously allocated memory
sizenew size for the allocated memory
Returns
the newly allocated memory