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 LLVM_LIBC_FUNCTION(char *, strrchr, (const char *src, int c)) { 16 const char ch = static_cast<char>(c); 17 char *last_occurrence = nullptr; 18 for (; *src; ++src) { 19 if (*src == ch) 20 last_occurrence = const_cast<char *>(src); 21 } 22 return last_occurrence; 23 } 24 25 } // namespace __llvm_libc 26