summaryrefslogtreecommitdiff
path: root/zap/src/memcmp.c
blob: 0fdf13a01bea19848efe949af3b0c65fd79a60e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
	Copyright 2022 Gabriel Jensen.
	This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
	If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#include <zap/priv.h>

#include <zap/mem.h>

#include <stddef.h>

int_least8_t zap_memcmp(void const * const _lstr,size_t const _num,void const * const _rstr) {
	unsigned char const *       lpos      = _lstr;
	unsigned char const *       rpos      = _rstr;
	unsigned char const * const afterlbuf = lpos + _num;
	for (;lpos != afterlbuf;++lpos,++rpos) {
		unsigned char const lbyte = *lpos;
		unsigned char const rbyte = *rpos;
		sus_likely (lbyte != rbyte) {return lbyte < rbyte ? INT_LEAST8_MIN : INT_LEAST8_MAX;}
	}
	return 0x0;
}