/* The memchr() function scans the initial n bytes of the memory area pointed to by s for the first instance of c. Both c and the bytes of the memory area pointed to by s are interpreted as unsigned char.  */
void* memrchr(const void *ptr, int ch, size_t pos)
/* The memchr() function scans the initial n bytes of the memory area pointed to by s for the first instance of c. Both c and the bytes of the memory area pointed to by s are interpreted as unsigned char.  */
void* memrchr(const void *ptr, int ch, size_t pos)
{
    char* end = (char*)ptr + pos - 1;
    while (end != ptr)
    {
        if (*end == ch)
            return end;
        end--;
    }
    return (*end == ch) ? (end) : (NULL);
}