/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2007, 2010-20144* Todd C. Miller <[email protected]>5*6* Permission to use, copy, modify, and distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/1819#include <config.h>2021#ifndef HAVE_MEMRCHR2223#include <sys/types.h>2425#include <sudo_compat.h>2627/*28* Reverse memchr()29* Find the last occurrence of 'c' in the buffer 's' of size 'n'.30*/31void *32sudo_memrchr(const void *s, int c, size_t n)33{34const unsigned char *cp;3536if (n != 0) {37cp = (unsigned char *)s + n;38do {39if (*(--cp) == (unsigned char)c)40return (void *)cp;41} while (--n != 0);42}43return (void *)0;44}45#endif /* HAVE_MEMRCHR */464748