XBinder  Version 2.9.x
Functions
Character string functions

These functions are more secure versions of several of the character string functions available in the standard C run-time library. More...

Functions

EXTERNRT int rtxStricmp (const char *str1, const char *str2)
 This is an implementation of the non-standard stricmp function. More...
 
EXTERNRT int rtxStrnicmp (const char *str1, const char *str2, size_t count)
 This is an implementation of the non-standard stricmp function. More...
 
EXTERNRT char * rtxStrcat (char *dest, size_t bufsiz, const char *src)
 This function concatanates the given string onto the string buffer. More...
 
EXTERNRT 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. More...
 
EXTERNRT char * rtxStrcpy (char *dest, size_t bufsiz, const char *src)
 This function copies a null-terminated string to a target buffer. More...
 
EXTERNRT 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. More...
 
EXTERNRT char * rtxStrdup (OSCTXT *pctxt, const char *src)
 This function creates a duplicate copy of a null-terminated string. More...
 
EXTERNRT char * rtxStrndup (OSCTXT *pctxt, const char *src, OSSIZE nchars)
 This function creates a duplicate copy of up to the given number of characters in a string. More...
 
EXTERNRT 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. More...
 
EXTERNRT 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. More...
 
EXTERNRT char * rtxStrTrimEnd (char *s)
 This function trims whitespace from the end of a string. More...
 
EXTERNRT int rtxValidateConstrainedStr (OSCTXT *pctxt, const char *pvalue, const char *pCharSet)
 This function will validate a constrained character string by checking to see if all the characters in the given string are contained within the

constraining character set.

More...
 
EXTERNRT int rtxIntToCharStr (OSINT32 value, char *dest, size_t bufsiz, char padchar)
 This function converts a signed 32-bit integer into a character string. More...
 
EXTERNRT int rtxUIntToCharStr (OSUINT32 value, char *dest, size_t bufsiz, char padchar)
 This function converts an unsigned 32-bit integer into a character string. More...
 
EXTERNRT int rtxInt64ToCharStr (OSINT64 value, char *dest, size_t bufsiz, char padchar)
 This function converts a signed 64-bit integer into a character string. More...
 
EXTERNRT int rtxUInt64ToCharStr (OSUINT64 value, char *dest, size_t bufsiz, char padchar)
 This function converts an unsigned 64-bit integer into a character string. More...
 
EXTERNRT 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. More...
 
EXTERNRT 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. More...
 
EXTERNRT int rtxHexCharsToBin (const char *hexstr, size_t nchars, OSOCTET *binbuf, size_t bufsize)
 This function converts the given hex string to binary. More...
 
EXTERNRT int rtxCharStrToInt (const char *cstr, OSINT32 *pvalue)
 This function converts the given character string to a signed 32-bit integer value. More...
 
EXTERNRT int rtxCharStrnToInt (const char *cstr, OSSIZE ndigits, OSINT32 *pvalue)
 This function converts up to the given number of digits from the given character string to a signed 32-bit integer value. More...
 
EXTERNRT int rtxCharStrToInt8 (const char *cstr, OSINT8 *pvalue)
 This function converts the given character string to a signed 8-bit integer value. More...
 
EXTERNRT int rtxCharStrToInt16 (const char *cstr, OSINT16 *pvalue)
 This function converts the given character string to a signed 16-bit integer value. More...
 
EXTERNRT int rtxCharStrToInt64 (const char *cstr, OSINT64 *pvalue)
 This function converts the given character string to a signed 64-bit integer value. More...
 
EXTERNRT int rtxCharStrToUInt (const char *cstr, OSUINT32 *pvalue)
 This function converts the given character string to an unsigned 32-bit integer value. More...
 
EXTERNRT int rtxCharStrToUInt8 (const char *cstr, OSUINT8 *pvalue)
 This function converts the given character string to an unsigned 8-bit integer value. More...
 
EXTERNRT int rtxCharStrToUInt16 (const char *cstr, OSUINT16 *pvalue)
 This function converts the given character string to an unsigned 16-bit integer value. More...
 
EXTERNRT int rtxCharStrToUInt64 (const char *cstr, OSUINT64 *pvalue)
 This function converts the given character string to an unsigned 64-bit integer value. More...
 

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

◆ rtxCharStrnToInt()

EXTERNRT int rtxCharStrnToInt ( const char *  cstr,
OSSIZE  ndigits,
OSINT32 *  pvalue 
)

This function converts up to the given number of digits from the given character string to a signed 32-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until either the number of digits is reached or a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
ndigitsNumber of digits to convert.
pvaluePointer to integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToInt()

EXTERNRT int rtxCharStrToInt ( const char *  cstr,
OSINT32 *  pvalue 
)

This function converts the given character string to a signed 32-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToInt16()

EXTERNRT int rtxCharStrToInt16 ( const char *  cstr,
OSINT16 *  pvalue 
)

This function converts the given character string to a signed 16-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 16-bit integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToInt64()

EXTERNRT int rtxCharStrToInt64 ( const char *  cstr,
OSINT64 *  pvalue 
)

This function converts the given character string to a signed 64-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 64-bit integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToInt8()

EXTERNRT int rtxCharStrToInt8 ( const char *  cstr,
OSINT8 *  pvalue 
)

This function converts the given character string to a signed 8-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 8-bit integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToUInt()

EXTERNRT int rtxCharStrToUInt ( const char *  cstr,
OSUINT32 *  pvalue 
)

This function converts the given character string to an unsigned 32-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 32-bit unsigned integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToUInt16()

EXTERNRT int rtxCharStrToUInt16 ( const char *  cstr,
OSUINT16 *  pvalue 
)

This function converts the given character string to an unsigned 16-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 16-bit unsigned integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToUInt64()

EXTERNRT int rtxCharStrToUInt64 ( const char *  cstr,
OSUINT64 *  pvalue 
)

This function converts the given character string to an unsigned 64-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 64-bit unsigned integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxCharStrToUInt8()

EXTERNRT int rtxCharStrToUInt8 ( const char *  cstr,
OSUINT8 *  pvalue 
)

This function converts the given character string to an unsigned 8-bit integer value.

It consumes all leading whitespace before the digits start. It then comsumes digits until a non-digit character is encountered.

Parameters
cstrCharacter string to convert.
pvaluePointer to 8-bit unsigned integer value to receive converted data.
Returns
Number of bytes or negative status value if fail.

◆ rtxHexCharsToBin()

EXTERNRT 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
hexstrHex character string to convert.
ncharsNumber of characters in string. If zero, characters are read up to null-terminator.
binbufBuffer to hold converted binary data.
bufsizeSize of the binary data buffer.
Returns
Number of bytes or negative status value if fail.

◆ rtxHexCharsToBinCount()

EXTERNRT 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
hexstrHex character string to convert.
ncharsNumber of characters in string. If zero, characters are read up to null-terminator.
Returns
Number of bytes or negative status value if fail.

◆ rtxInt64ToCharStr()

EXTERNRT 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
valueInteger to convert.
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
padcharLeft pad char, set to zero for no padding.
Returns
Number of characters or negative status value if fail.

◆ rtxIntToCharStr()

EXTERNRT 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
valueInteger to convert.
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
padcharLeft pad char, set to zero for no padding.
Returns
Number of characters or negative status value if fail.

◆ rtxSizeToCharStr()

EXTERNRT 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
valueSize value to convert.
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
padcharLeft pad char, set to zero for no padding.
Returns
Number of characters or negative status value if fail.

◆ rtxStrcat()

EXTERNRT 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
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
srcPointer to null-terminated string to copy.
Returns
Pointer to destination buffer or NULL if copy failed.

◆ rtxStrcpy()

EXTERNRT 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
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
srcPointer to null-terminated string to copy.
Returns
Pointer to destination buffer or NULL if copy failed.

◆ rtxStrdup()

EXTERNRT 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
pctxtPointer to a standard context structure.
srcPointer to null-terminated string to copy.
Returns
Pointer to destination buffer or NULL if copy failed.

◆ rtxStrDynJoin()

EXTERNRT 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
pctxtPointer to a standard context structure.
str1Pointer to substring to join.
str2Pointer to substring to join.
str3Pointer to substring to join.
str4Pointer to substring to join.
str5Pointer to substring to join.
Returns
Composite string consisting of all parts.

◆ rtxStricmp()

EXTERNRT 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
str1Pointer to first string to compare.
str2Pointer to second string to compare.
Returns
0 if strings are equal, non-zero if not.

◆ rtxStrJoin()

EXTERNRT 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
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
str1Pointer to substring to join.
str2Pointer to substring to join.
str3Pointer to substring to join.
str4Pointer to substring to join.
str5Pointer to substring to join.
Returns
Composite string consisting of all parts.

◆ rtxStrncat()

EXTERNRT 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
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
srcPointer to null-terminated string to copy.
ncharsNumber of characters to copy.
Returns
Pointer to destination buffer or NULL if copy failed.

◆ rtxStrncpy()

EXTERNRT 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
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
srcPointer to null-terminated string to copy.
ncharsNumber of characters to copy.
Returns
Pointer to destination buffer or NULL if copy failed.

◆ rtxStrndup()

EXTERNRT char* rtxStrndup ( OSCTXT pctxt,
const char *  src,
OSSIZE  nchars 
)

This function creates a duplicate copy of up to the given number of characters in a string.

The string does not need to be null-terminated. 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 strndup function except more secure because it checks for buffer overrun.

Parameters
pctxtPointer to a standard context structure.
srcPointer to null-terminated string to copy.
Returns
Pointer to destination buffer or NULL if copy failed.

◆ rtxStrnicmp()

EXTERNRT int rtxStrnicmp ( const char *  str1,
const char *  str2,
size_t  count 
)

This is an implementation of the non-standard stricmp function.

It does not check for greater than/less than however, only for equality.

Parameters
str1Pointer to first string to compare.
str2Pointer to second string to compare.
countNumber of characters to compare, at most.
Returns
0 if strings are equal, non-zero if not.

◆ rtxStrTrimEnd()

EXTERNRT char* rtxStrTrimEnd ( char *  s)

This function trims whitespace from the end of a string.

Parameters
sPointer to string to be trimmed.
Returns
Point to string s.

◆ rtxUInt64ToCharStr()

EXTERNRT 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
valueInteger to convert.
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
padcharLeft pad char, set to zero for no padding.
Returns
Number of characters or negative status value if fail.

◆ rtxUIntToCharStr()

EXTERNRT 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
valueInteger to convert.
destPointer to destination buffer to receive string.
bufsizSize of the destination buffer.
padcharLeft pad char, set to zero for no padding.
Returns
Number of characters or negative status value if fail.

◆ rtxValidateConstrainedStr()

EXTERNRT int rtxValidateConstrainedStr ( OSCTXT pctxt,
const char *  pvalue,
const char *  pCharSet 
)

This function will validate a constrained character string by checking to see if all the characters in the given string are contained within the

constraining character set.

Parameters
pctxtPointer to a context block structure. This provides a storage area for the function to store all working variables that must be maintained between function calls.
pvalueA pointer to a null-terminated C character string to be validated.
pCharSetA pointer to a null-terminated C character string containing the character set to validate against.
Returns
Status of the validation attempt. A negative status value will be returned if validation is not successful.