1 //===-- Implementation of strrchr------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/string/strrchr.h" 10 11 #include "src/__support/common.h" 12 13 namespace __llvm_libc { 14 15 char *LLVM_LIBC_ENTRYPOINT(strrchr)(const char *src, int c) { 16 unsigned char *str = 17 const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(src)); 18 const unsigned char ch = c; 19 20 unsigned char *last_occurrence = nullptr; 21 do { 22 if (*str == ch) 23 last_occurrence = str; 24 } while (*str++); 25 return reinterpret_cast<char *>(last_occurrence); 26 } 27 28 } // namespace __llvm_libc 29