libgslutil  1.2.3
Functions
Length-limited string operations.

Functions

size_t safe_strlcpy (char *dest, const char *src, size_t dest_size)
 Copy source to destination, limit by length. More...
 
size_t safe_strlcat (char *dest, const char *src, size_t dest_size)
 Catenate source onto destination, limit by length. More...
 

Detailed Description

An implementation of strlcpy() and strlcat().

Function Documentation

◆ safe_strlcpy()

size_t safe_strlcpy ( char *  dest,
const char *  src,
size_t  dest_size 
)

Copy source to destination, limit by length.

Parameters
destPointer to destination buffer.
srcPointer to source string.
dest_sizeSize of destination buffer in bytes.
Returns
Length of source string excluding terminating null.

Like strcpy(3) except it will never write more than dest_size bytes to dest (i.e. the result is truncated if it would not fit) and as long as dest_size is not zero then dest will always be null terminated.

Warning
Consider carefully the ramifications of source string truncation when using this function.

◆ safe_strlcat()

size_t safe_strlcat ( char *  dest,
const char *  src,
size_t  dest_size 
)

Catenate source onto destination, limit by length.

Parameters
destPointer to destination buffer.
srcPointer to source string.
dest_sizeSize of destination buffer in bytes.
Returns
Length of theoretical resultant string excluding terminating null.

Like strcat(3) except it will never write more than dest_size bytes to dest (i.e. the result is truncated if it would not fit) and as long as dest_size is not zero then dest will always be null terminated.

Warning
Consider carefully the ramifications of source string truncation when using this function.