1 //===-- Implementation of strstr ------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strstr.h"
11 #include "src/__support/common.h"
14 namespace __llvm_libc
{
16 // TODO: This is a simple brute force implementation. This can be
17 // improved upon using well known string matching algorithms.
18 char *LLVM_LIBC_ENTRYPOINT(strstr
)(const char *haystack
, const char *needle
) {
19 for (size_t i
= 0; haystack
[i
]; ++i
) {
21 for (j
= 0; haystack
[i
+ j
] && haystack
[i
+ j
] == needle
[j
]; ++j
)
24 return const_cast<char *>(haystack
+ i
);
29 } // namespace __llvm_libc