Path: blob/main/system/lib/llvm-libc/src/string/memrchr.cpp
6175 views
//===-- Implementation of memrchr -----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "src/string/memrchr.h"9#include "src/__support/common.h"10#include "src/__support/macros/config.h"11#include "src/__support/macros/null_check.h"12#include <stddef.h>1314namespace LIBC_NAMESPACE_DECL {1516LLVM_LIBC_FUNCTION(void *, memrchr, (const void *src, int c, size_t n)) {1718if (n)19LIBC_CRASH_ON_NULLPTR(src);2021const unsigned char *str = reinterpret_cast<const unsigned char *>(src);22const unsigned char ch = static_cast<unsigned char>(c);23for (; n != 0; --n) {24const unsigned char *s = str + n - 1;25if (*s == ch)26return const_cast<unsigned char *>(s);27}28return nullptr;29}3031} // namespace LIBC_NAMESPACE_DECL323334