Open n7ekb opened 7 months ago
IMO strnstr(haystack, needle, strlen(haystack)) is quite silly. strstr() would stop when it finds a null terminator. There is no point in scanning the string first to find the null terminator, and then telling strnstr where to stop while it scans it again. Just use strstr(), which is more portable in the first place.
It may be true that strnstr() is "safer" (prevent buffer overrun in case the null terminator is missing or got overwritten due to some other bug), but then you give a constant: the maximum limit for the string size, such as the size of a fixed buffer into which it is stored. And yeah for some reason libc doesn't include strnstr().
(https://github.com/OpenRTX/dmrconfig/issues/77)
Provides BSD strnstr() function if not defined by build environment's C library.