Character string functions
Functions | |
int | rtxStricmp (const char *str1, const char *str2) |
char * | rtxStrcat (char *dest, size_t bufsiz, const char *src) |
char * | rtxStrncat (char *dest, size_t bufsiz, const char *src, size_t nchars) |
char * | rtxStrcpy (char *dest, size_t bufsiz, const char *src) |
char * | rtxStrncpy (char *dest, size_t bufsiz, const char *src, size_t nchars) |
char * | rtxStrdup (OSCTXT *pctxt, const char *src) |
const char * | rtxStrJoin (char *dest, size_t bufsiz, const char *str1, const char *str2, const char *str3, const char *str4, const char *str5) |
const char * | rtxStrDynJoin (OSCTXT *pctxt, const char *str1, const char *str2, const char *str3, const char *str4, const char *str5) |
int | rtxIntToCharStr (OSINT32 value, char *dest, size_t bufsiz, char padchar) |
int | rtxUIntToCharStr (OSUINT32 value, char *dest, size_t bufsiz, char padchar) |
int | rtxInt64ToCharStr (OSINT64 value, char *dest, size_t bufsiz, char padchar) |
int | rtxUInt64ToCharStr (OSUINT64 value, char *dest, size_t bufsiz, char padchar) |
int | rtxSizeToCharStr (size_t value, char *dest, size_t bufsiz, char padchar) |
int | rtxHexCharsToBinCount (const char *hexstr, size_t nchars) |
int | rtxHexCharsToBin (const char *hexstr, size_t nchars, OSOCTET *binbuf, size_t bufsize) |
int | rtxCharStrToInt (const char *cstr, OSINT32 *pvalue) |
int | rtxCharStrToInt8 (const char *cstr, OSINT8 *pvalue) |
int | rtxCharStrToInt16 (const char *cstr, OSINT16 *pvalue) |
int | rtxCharStrToUInt (const char *cstr, OSUINT32 *pvalue) |
int | rtxCharStrToUInt8 (const char *cstr, OSUINT8 *pvalue) |
int | rtxCharStrToUInt16 (const char *cstr, OSUINT16 *pvalue) |
Detailed Description
These functions are more secure versions of several of the character string functions available in the standard C run-time library.
Function Documentation
int rtxCharStrToInt | ( | const char * | cstr, | |
OSINT32 * | pvalue | |||
) |
This function converts the given character string to an integer value. It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.
- Parameters:
-
cstr Character string to convert. pvalue Pointer to integer value to receive converted data.
- Returns:
- Number of bytes or negative status value if fail.
int rtxHexCharsToBin | ( | const char * | hexstr, | |
size_t | nchars, | |||
OSOCTET * | binbuf, | |||
size_t | bufsize | |||
) |
This function converts the given hex string to binary. The result is stored in the given binary buffer. Any whitespace characters in the string are ignored.
- Parameters:
-
hexstr Hex character string to convert. nchars Number of characters in string. If zero, characters are read up to null-terminator. binbuf Buffer to hold converted binary data. bufsize Size of the binary data buffer.
- Returns:
- Number of bytes or negative status value if fail.
int rtxHexCharsToBinCount | ( | const char * | hexstr, | |
size_t | nchars | |||
) |
This function returns a count of the number of bytes the would result from the conversion of a hexadecimal character string to binary. Any whitespace characters in the string are ignored.
- Parameters:
-
hexstr Hex character string to convert. nchars Number of characters in string. If zero, characters are read up to null-terminator.
- Returns:
- Number of bytes or negative status value if fail.
int rtxInt64ToCharStr | ( | OSINT64 | value, | |
char * | dest, | |||
size_t | bufsiz, | |||
char | padchar | |||
) |
This function converts a signed 64-bit integer into a character string. It is similar to the C itoa
function.
- Parameters:
-
value Integer to convert. dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. padchar Left pad char, set to zero for no padding.
- Returns:
- Number of characters or negative status value if fail.
int rtxIntToCharStr | ( | OSINT32 | value, | |
char * | dest, | |||
size_t | bufsiz, | |||
char | padchar | |||
) |
This function converts a signed 32-bit integer into a character string. It is similar to the C itoa
function.
- Parameters:
-
value Integer to convert. dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. padchar Left pad char, set to zero for no padding.
- Returns:
- Number of characters or negative status value if fail.
int rtxSizeToCharStr | ( | size_t | value, | |
char * | dest, | |||
size_t | bufsiz, | |||
char | padchar | |||
) |
This function converts a value of type 'size_t' into a character string. It is similar to the C itoa
function.
- Parameters:
-
value Size value to convert. dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. padchar Left pad char, set to zero for no padding.
- Returns:
- Number of characters or negative status value if fail.
char* rtxStrcat | ( | char * | dest, | |
size_t | bufsiz, | |||
const char * | src | |||
) |
This function concatanates the given string onto the string buffer. It is similar to the C strcat
function except more secure because it checks for buffer overrun.
- Parameters:
-
dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. src Pointer to null-terminated string to copy.
- Returns:
- Pointer to destination buffer or NULL if copy failed.
char* rtxStrcpy | ( | char * | dest, | |
size_t | bufsiz, | |||
const char * | src | |||
) |
This function copies a null-terminated string to a target buffer. It is similar to the C strcpy
function except more secure because it checks for buffer overrun.
- Parameters:
-
dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. src Pointer to null-terminated string to copy.
- Returns:
- Pointer to destination buffer or NULL if copy failed.
char* rtxStrdup | ( | OSCTXT * | pctxt, | |
const char * | src | |||
) |
This function creates a duplicate copy of a null-terminated string. Memory is allocated for the target string using the rtxMemAlloc function. The string is then copied into this memory block. It is similar to the C strdup
function except more secure because it checks for buffer overrun.
- Parameters:
-
pctxt Pointer to a standard context structure. src Pointer to null-terminated string to copy.
- Returns:
- Pointer to destination buffer or NULL if copy failed.
const char* rtxStrDynJoin | ( | OSCTXT * | pctxt, | |
const char * | str1, | |||
const char * | str2, | |||
const char * | str3, | |||
const char * | str4, | |||
const char * | str5 | |||
) |
This function allocates memory for and concatanates up to five substrings together into a single string.
- Parameters:
-
pctxt Pointer to a standard context structure. str1 Pointer to substring to join. str2 Pointer to substring to join. str3 Pointer to substring to join. str4 Pointer to substring to join. str5 Pointer to substring to join.
- Returns:
- Composite string consisting of all parts.
int rtxStricmp | ( | const char * | str1, | |
const char * | str2 | |||
) |
This is an implementation of the non-standard stricmp function. It does not check for greater than/less than however, only for equality.
- Parameters:
-
str1 Pointer to first string to compare. str2 Pointer to second string to compare.
- Returns:
- 0 if strings are equal, non-zero if not.
const char* rtxStrJoin | ( | char * | dest, | |
size_t | bufsiz, | |||
const char * | str1, | |||
const char * | str2, | |||
const char * | str3, | |||
const char * | str4, | |||
const char * | str5 | |||
) |
This function concatanates up to five substrings together into a single string.
- Parameters:
-
dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. str1 Pointer to substring to join. str2 Pointer to substring to join. str3 Pointer to substring to join. str4 Pointer to substring to join. str5 Pointer to substring to join.
- Returns:
- Composite string consisting of all parts.
char* rtxStrncat | ( | char * | dest, | |
size_t | bufsiz, | |||
const char * | src, | |||
size_t | nchars | |||
) |
This function concatanates the given number of characters from the given string onto the string buffer. It is similar to the C strncat
function except more secure because it checks for buffer overrun.
- Parameters:
-
dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. src Pointer to null-terminated string to copy. nchars Number of characters to copy.
- Returns:
- Pointer to destination buffer or NULL if copy failed.
char* rtxStrncpy | ( | char * | dest, | |
size_t | bufsiz, | |||
const char * | src, | |||
size_t | nchars | |||
) |
This function copies the given number of characters from a string to a target buffer. It is similar to the C strncpy
function except more secure because it checks for buffer overrun and ensures a null-terminator is copied to the end of the target buffer. If the target buffer is too short to hold the null terminator, the last character is overwritten and a null pointer is returned; the destination buffer can still be examined in this case.
- Parameters:
-
dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. src Pointer to null-terminated string to copy. nchars Number of characters to copy.
- Returns:
- Pointer to destination buffer or NULL if copy failed.
int rtxUInt64ToCharStr | ( | OSUINT64 | value, | |
char * | dest, | |||
size_t | bufsiz, | |||
char | padchar | |||
) |
This function converts an unsigned 64-bit integer into a character string. It is similar to the C itoa
function.
- Parameters:
-
value Integer to convert. dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. padchar Left pad char, set to zero for no padding.
- Returns:
- Number of characters or negative status value if fail.
int rtxUIntToCharStr | ( | OSUINT32 | value, | |
char * | dest, | |||
size_t | bufsiz, | |||
char | padchar | |||
) |
This function converts an unsigned 32-bit integer into a character string. It is similar to the C itoa
function.
- Parameters:
-
value Integer to convert. dest Pointer to destination buffer to receive string. bufsiz Size of the destination buffer. padchar Left pad char, set to zero for no padding.
- Returns:
- Number of characters or negative status value if fail.