Str_Len_N()
Determines the length of a string, up to a maximum number of characters.
Files
lib_str.h/lib_str.c
Prototype
CPU_SIZE_T Str_Len_N (const CPU_CHAR *pstr, CPU_SIZE_T len_max);
Arguments
pstr
Pointer to the string.
len_max
Maximum number of string characters to search.
Returned Value
Length of string, in number of characters, before, but not including, the terminating NULL
character; if terminating NULL
character found;
Maximum number of characters to search, if terminating NULL
character not found.
Required Configuration
None.
Notes / Warnings
String buffer not modified.
The maximum number of characters to search does not include the terminating NULL
character. Therefore, if Str_Len()
returns the maximum number of search characters, then the string is not NULL
-terminated within the maximum number of search characters.
String length calculation terminates if string pointer points to or overlaps the NULL
address.
Example Usage
CPU_SIZE_T len; len = Str_Len_N("SomeString", MAX_SIZE); if (len >= MAX_SIZE) { printf("STRING IS TOO LONG!"); }