Functions

src/libmcs/mcs_util.c File Reference

#include "libmcs/mcs.h"

Functions

size_t mcs_strnlen (const char *str, size_t len)
 Determines the length of a string, limited by an arbitrary length.
char * mcs_strndup (const char *str, size_t len)
 Duplicates a string, limited to a specific length.
int mcs_create_directory (const char *path, mode_t mode)
 A utility function which creates a directory.
size_t mcs_strlcat (char *dest, const char *src, size_t count)
 Concatenates a string, limited to a maximum buffer size.
size_t mcs_strlcpy (char *dest, const char *src, size_t size)
 Copies a string, limited to a maximum buffer size.

Function Documentation

int mcs_create_directory ( const char *  path,
mode_t  mode 
)

A utility function which creates a directory.

This function creates a directory. It recurses to handle any parents which also need to be created.

Parameters:
path The path to create.
mode The mode of the directory that should be created.
Returns:
0 on success, -1 on failure.

References mcs_strndup().

size_t mcs_strlcat ( char *  dest,
const char *  src,
size_t  count 
)

Concatenates a string, limited to a maximum buffer size.

This is a function which is useful for safely copying a string.

Parameters:
dest The string to copy to.
src The string to copy from.
count The maximum allowed length of the string.
Returns:
The length of the new string.
size_t mcs_strlcpy ( char *  dest,
const char *  src,
size_t  size 
)

Copies a string, limited to a maximum buffer size.

This is a function which is useful for safely copying a string.

Parameters:
dest The string to copy to.
src The string to copy from.
size The maximum allowed length of the string.
Returns:
The length of the new string.
char* mcs_strndup ( const char *  str,
size_t  len 
)

Duplicates a string, limited to a specific length.

This is a function which duplicates a string limited to a maximum length.

Parameters:
str The string to duplicate.
len The maximum allowed length of the string.
Returns:
The pointer to a copy of the string. Free this with free().

References mcs_strnlen().

Referenced by mcs_create_directory().

size_t mcs_strnlen ( const char *  str,
size_t  len 
)

Determines the length of a string, limited by an arbitrary length.

This is a function which is useful for limiting the length of a string.

Parameters:
str The string to test.
len The maximum allowed length of the string.
Returns:
The length of the string or len, whichever is smaller.

Referenced by mcs_strndup().