Tool/software: TI C/C++ Compiler
Does the TI arm compiler not support strnlen? I’ve included string.h but I don’t see the function listed in there and I’m getting an error saying it can’t find it.
Best Regards, Blake
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Does the TI arm compiler not support strnlen? I’ve included string.h but I don’t see the function listed in there and I’m getting an error saying it can’t find it.
Best Regards, Blake
I would not be surprised if it wasn't offered, I don't think it is part of standard C or C++. C11 has a similar function, strnlen_s, but that likely has not made its way to the CGT yet.
You can likely find source for a generic implementation online; or you might role your own, perhaps using memchr. Depending on the use-case, you might be able to spice things up with optimizations like MUST_ITERATE and restrict _nassert.
I found an implementation that seems to work. I made some slight modifications and put it in a platform_config header so that I can just add a predefined symbol (MY_STRNLEN) if the compiler doesn't have strnlen
#ifdef MY_STRNLEN
static inline size_t strnlen (const char *string, size_t length)
{
char *ret = memchr (string, 0, length);
return ret ? ret - string : length;
}
#endif
Thanks for sharing.
Unfortunately, no variant of strnlen is in the TI compiler RTS library, and there are no plans to add one.
Thanks and regards,
-George