Check for strnlen and provide it if it is not found

strnlen is POSIX.1-2008. Thus on some older/incompatible systems, this function is not defined. E.g. current mingw (see http://sourceforge.net/p/mingw/bugs/1912/) or on older Mac OS X. Check for such conditions and use memchr based implementation instead. This should fix #5338.