1 //===-- Implementation of bcmp --------------------------------------------===//
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/bcmp.h"
10 #include "src/__support/common.h"
11 
12 namespace __llvm_libc {
13 
14 LLVM_LIBC_FUNCTION(int, bcmp,
15                    (const void *lhs, const void *rhs, size_t count)) {
16   const unsigned char *_lhs = reinterpret_cast<const unsigned char *>(lhs);
17   const unsigned char *_rhs = reinterpret_cast<const unsigned char *>(rhs);
18   for (size_t i = 0; i < count; ++i) {
19     if (_lhs[i] != _rhs[i]) {
20       return 1;
21     }
22   }
23   // count is 0 or _lhs and _rhs are the same.
24   return 0;
25 }
26 
27 } // namespace __llvm_libc
28