OpenCBM
Functions
libmisc.h File Reference

Some functions for string handling. More...

#include <stddef.h>

Go to the source code of this file.

Functions

char * cbmlibmisc_stralloc (unsigned int Length)
 allocate memory for a string of a given size More...
 
char * cbmlibmisc_strdup (const char *const OldString)
 Duplicate a given string. More...
 
char * cbmlibmisc_strndup (const char *const OldString, size_t Length)
 Duplicate a prefix of a given string. More...
 
void cbmlibmisc_strfree (const char *String)
 Free a string. More...
 
char * cbmlibmisc_strcat (const char *first, const char *second)
 Concatenate two strings. More...
 
char * cbmlibmisc_format_error_message (unsigned int ErrorNumber)
 Format a returned error code into a string. More...
 

Detailed Description

Some functions for string handling.



Author
Spiro Trikaliotis

Definition in file libmisc.h.

Function Documentation

char* cbmlibmisc_format_error_message ( unsigned int  ErrorNumber)

Format a returned error code into a string.

This function formats a returned error code into a string.

Parameters
ErrorThe error number to be formatted.
Returns
The string describing the error given by the error code.

Definition at line 35 of file formaterrormessage.c.

Referenced by CbmInstall(), CbmRemove(), and plugin_load().

char* cbmlibmisc_stralloc ( unsigned int  Length)

allocate memory for a string of a given size

This function allocates memory for a string with a given size.

Parameters
LengthThe size of the string. The trailing zero does not count, that is, extra space for an additional zero is allocated.
Returns
NULL on failure; otherwise, a pointer to the newly allocated memory.
Remarks
The string must be freed with cbmlibmisc_strfree().

Definition at line 41 of file libstring.c.

char* cbmlibmisc_strcat ( const char *  First,
const char *  Second 
)

Concatenate two strings.

This function concatenates two strings and returns the result in a malloc()ed memory region.

Parameters
FirstThe first string to concatenate. If this pointer is NULL, an empty string is assumed.
SecondThe second string to concatenate. If this pointer is NULL, an empty string is assumed.
Returns
The malloc()ed memory for the concatenated string, or NULL if there was not enough memory.
Remarks
The string must be freed with cbmlibmisc_strfree().

Definition at line 202 of file libstring.c.

Referenced by cbm_get_debugging_flags(), configuration_get_default_filename(), opencbm_configuration_open(), and opencbm_plugin_install_do_install().

char* cbmlibmisc_strdup ( const char *const  OldString)

Duplicate a given string.

This function allocates memory for a string. This string is initialised with a copy of the given parameter string.

Parameters
OldStringThe string to duplicate. Can also be NULL.
Returns
NULL on failure; otherwise, a pointer to the newly allocated string.
Remarks
If OldString is given as a NULL pointer, this function allocates an empty string (not a NULL pointer)
The string must be freed with cbmlibmisc_strfree().

Definition at line 84 of file libstring.c.

Referenced by cbm_get_debugging_flags(), cbm_get_driver_name_ex(), cbmlibmisc_strndup(), configuration_get_default_filename(), opencbm_configuration_get_data(), opencbm_configuration_open(), and opencbm_configuration_set_data().

void cbmlibmisc_strfree ( const char *  String)

Free a string.

This function frees a string which has been previously allocated by any of the functions in this file.

Parameters
StringA pointer to the string to be freed.

Definition at line 172 of file libstring.c.

Referenced by cbm_driver_open_ex(), cbm_get_debugging_flags(), cbm_get_driver_name_ex(), get_all_plugins(), opencbm_configuration_open(), opencbm_configuration_set_data(), opencbm_plugin_get_all_plugin_names(), opencbm_plugin_install_do_install(), opencbm_plugin_install_generic(), opencbm_plugin_install_plugin_data(), and plugin_is_active().

char* cbmlibmisc_strndup ( const char *const  OldString,
size_t  Length 
)

Duplicate a prefix of a given string.

This function allocates memory for a string. This string is initialised with a copy of a prefix of the given parameter string.

Parameters
OldStringThe string to duplicate. Can also be NULL.
LengthThe size of the prefix to copy.
Returns
NULL on failure; otherwise, a pointer to the newly allocated string.
Remarks
If the OldString has Length characters or more, the first Length characters are returned in the new copy of the string.

If the OldString has less than Length characters, a full copy of OldString is returned.

Remarks
If OldString is given as a NULL pointer, this function allocates an empty string (not a NULL pointer)
The string must be freed with cbmlibmisc_strfree().

Definition at line 136 of file libstring.c.

References cbmlibmisc_strdup().