C Standard Library Extensions
1.2.4
|
Functions | |
const cxchar * | cx_program_get_name (void) |
Get the name of the application. More... | |
void | cx_program_set_name (const cxchar *name) |
Set the name of the application. More... | |
cxint | cx_bits_find (cxuint32 mask, cxint start) |
Get the position of the first bit set, searching from left to right. More... | |
cxint | cx_bits_rfind (cxuint32 mask, cxint start) |
Get the position of the first bit set, searching from right to left. More... | |
cxint | cx_snprintf (cxchar *string, cxsize n, const cxchar *format,...) |
Safe version of sprintf(). More... | |
cxint | cx_vsnprintf (cxchar *string, cxsize n, const cxchar *format, va_list args) |
Safe version of vsprintf(). More... | |
cxint | cx_asprintf (cxchar **string, const cxchar *format,...) |
Write formatted output to a newly allocated string. More... | |
cxint | cx_vasprintf (cxchar **string, const cxchar *format, va_list args) |
Write formatted output to a newly allocated string with a variable-length argument list. More... | |
cxlong | cx_line_max (void) |
Get the maximum length of a line supported by the system. More... | |
cxchar * | cx_line_alloc (void) |
Allocate a line buffer with the maximum size supported by the system. More... | |
The module provides a portable implementation of a selection of miscellaneous utility functions.
cxint cx_asprintf | ( | cxchar ** | string, |
const cxchar * | format, | ||
... | |||
) |
Write formatted output to a newly allocated string.
string | Address where the allocated string is stored. |
format | The format string. |
... | Arguments to be inserted into the format string. |
The function is similar to cx_snprintf() or sprintf(). The difference to cx_snprintf() is that the output created from the format string format and the formatted arguments is placed into a string which is allocated using cx_malloc(). All standard C conversion directives are supported. The allocated string is always null terminated.
The pointer to the allocated string buffer sufficiently large to hold the string is returned to the caller in the string argument. This pointer should be passed to cx_free to release the allocated storage when it is no longer needed. If sufficient memory cannot be allocated is set to NULL
.
References cx_vasprintf().
cxint cx_bits_find | ( | cxuint32 | mask, |
cxint | start | ||
) |
Get the position of the first bit set, searching from left to right.
mask | A 32 bit integer containing bit flags. |
start | Bit position where the search starts. |
The function searches for the first bit set in mask, starting at the bit position start - 1. The bit mask mask is searched from left to right. If start is less than 0 or bigger than 32 the search starts at the 31st bit.
cxint cx_bits_rfind | ( | cxuint32 | mask, |
cxint | start | ||
) |
Get the position of the first bit set, searching from right to left.
mask | A 32 bit integer containing bit flags. |
start | Bit position where the search starts. |
The function searches for the first bit set in mask, starting at the bit position start + 1. The bit mask mask is searched from right to left. If start is less than 0 the search starts at the 1st bit.
cxchar* cx_line_alloc | ( | void | ) |
Allocate a line buffer with the maximum size supported by the system.
The function creates a line buffer with the maximum length supported by the system. The size of the buffer is determined calling cx_line_max() which gives the maximum size including the trailing zero.
References cx_calloc(), and cx_line_max().
cxlong cx_line_max | ( | void | ) |
Get the maximum length of a line supported by the system.
The function uses the sysconf() function to determine the maximum length of a line buffer that is supported by the system and available for utility programs. If the sysconf() facility is not available the function returns a guessed value of 4096 characters as the maximum length of a line taking into account the trailing zero.
Referenced by cx_line_alloc().
const cxchar* cx_program_get_name | ( | void | ) |
Get the name of the application.
The program's name is retrieved and returned to the caller. The returned pointer is a library resource and must not be freed or modified.
void cx_program_set_name | ( | const cxchar * | name | ) |
Set the name of the application.
name | The program name. |
The program's name is set to the string name.
cxint cx_snprintf | ( | cxchar * | string, |
cxsize | n, | ||
const cxchar * | format, | ||
... | |||
) |
Safe version of sprintf().
string | Destination string. |
n | Maximum number of characters to be written. |
format | The format string. |
... | Arguments to be inserted into the format string. |
The function is a safe form of sprintf(). It writes output to the string string, under the control of the format string format. The format string specifies how the arguments are formatted for output. All standard C conversion directives are supported.
The difference compared to sprintf() is that the produced number of characters does not exceed n (including the trailing null).
References cx_vsnprintf().
cxint cx_vasprintf | ( | cxchar ** | string, |
const cxchar * | format, | ||
va_list | args | ||
) |
Write formatted output to a newly allocated string with a variable-length argument list.
string | Address where the allocated string is stored. |
format | The format string. |
args | List of arguments to be inserted into the format string. |
The function is similar to cx_vsnprintf() or vsprintf(). The difference to cx_vsnprintf() is that the output, created from the format string format and the arguments given by the variable-length argument list args, is placed into a string which is allocated using cx_malloc(). All standard C conversion directives are supported. The allocated string is always null terminated.
The pointer to the allocated string buffer sufficiently large to hold the string is returned to the caller in the string argument. This pointer should be passed to cx_free to release the allocated storage when it is no longer needed. If sufficient memory cannot be allocated is set to NULL
.
References cx_malloc(), cx_memory_is_system_malloc(), cx_strdup(), and cx_vsnprintf().
Referenced by cx_asprintf(), and cx_strvdupf().
cxint cx_vsnprintf | ( | cxchar * | string, |
cxsize | n, | ||
const cxchar * | format, | ||
va_list | args | ||
) |
Safe version of vsprintf().
string | Destination string. |
n | Maximum number of characters to be written. |
format | The format string. |
args | List of arguments to be inserted into the format string. |
The function is a safe form of vsprintf(). It writes output to the string string, under the control of the format string format. The format string specifies how the arguments, provided through the variable-length argument list args, are formatted for output. All standard C conversion directives are supported.
The difference compared to vsprintf() is that the produced number of characters does not exceed n (including the trailing null).
Referenced by cx_snprintf(), and cx_vasprintf().