OpenRTX / dmrconfig

Configuration utility for DMR radios
BSD 3-Clause "New" or "Revised" License
240 stars 56 forks source link

Proposed fix to issue #77 Build Fail on Fedora #78

Open n7ekb opened 7 months ago

n7ekb commented 7 months ago

(https://github.com/OpenRTX/dmrconfig/issues/77)

Provides BSD strnstr() function if not defined by build environment's C library.

ec1oud commented 2 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().