1*c8f79892SGuillaume Chatelet //===-- Implementation of bcmp --------------------------------------------===//
2*c8f79892SGuillaume Chatelet //
3*c8f79892SGuillaume Chatelet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*c8f79892SGuillaume Chatelet // See https://llvm.org/LICENSE.txt for license information.
5*c8f79892SGuillaume Chatelet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*c8f79892SGuillaume Chatelet //
7*c8f79892SGuillaume Chatelet //===----------------------------------------------------------------------===//
8*c8f79892SGuillaume Chatelet 
9*c8f79892SGuillaume Chatelet #include "src/string/bcmp.h"
10*c8f79892SGuillaume Chatelet #include "src/__support/common.h"
11*c8f79892SGuillaume Chatelet 
12*c8f79892SGuillaume Chatelet namespace __llvm_libc {
13*c8f79892SGuillaume Chatelet 
14*c8f79892SGuillaume Chatelet LLVM_LIBC_FUNCTION(int, bcmp,
15*c8f79892SGuillaume Chatelet                    (const void *lhs, const void *rhs, size_t count)) {
16*c8f79892SGuillaume Chatelet   const unsigned char *_lhs = reinterpret_cast<const unsigned char *>(lhs);
17*c8f79892SGuillaume Chatelet   const unsigned char *_rhs = reinterpret_cast<const unsigned char *>(rhs);
18*c8f79892SGuillaume Chatelet   for (size_t i = 0; i < count; ++i) {
19*c8f79892SGuillaume Chatelet     if (_lhs[i] != _rhs[i]) {
20*c8f79892SGuillaume Chatelet       return 1;
21*c8f79892SGuillaume Chatelet     }
22*c8f79892SGuillaume Chatelet   }
23*c8f79892SGuillaume Chatelet   // count is 0 or _lhs and _rhs are the same.
24*c8f79892SGuillaume Chatelet   return 0;
25*c8f79892SGuillaume Chatelet }
26*c8f79892SGuillaume Chatelet 
27*c8f79892SGuillaume Chatelet } // namespace __llvm_libc
28