MemCompare
- Function
- October 8, 2025
Table of Contents
MemCompare
MemCompare
Description
Compare memory regions.
Parameters
Name | Direction | Description |
---|---|---|
p1 | in | First memory region. |
p2 | in | Second memory region. |
n | in | Number of bytes to compare. |
Success
Returns 0 if equal, <0 if p1<p2, >0 if p1>p2.
Failure
Function cannot fail - always returns comparison result.
Usage example (Cross-references)
- In
Memory.c:11
:
#include <Misra/Std/Log.h>
i32 MemCompare(const void *p1, const void *p2, size n) {
if (!p1 || !p2) {
LOG_FATAL("Invalid arguments");
- In
Memory.c:217
:
// Compare the substring
if (MemCompare(haystack + pos, needle, needle_len) == 0) {
return (char *)(haystack + pos);
}
- In
Str.c:187
:
static inline bool starts_with(const char *data, size data_len, const char *prefix, size prefix_len) {
return data_len >= prefix_len && MemCompare(data, prefix, prefix_len) == 0;
}
- In
Str.c:191
:
static inline bool ends_with(const char *data, size data_len, const char *suffix, size suffix_len) {
return data_len >= suffix_len && MemCompare(data + data_len - suffix_len, suffix, suffix_len) == 0;
}
- In
Str.c:232
:
while (i + match_len <= s->length && replaced < count) {
if (MemCompare(s->data + i, match, match_len) == 0) {
StrDeleteRange(s, i, match_len);
StrInsertCstr(s, replacement, i, replacement_len);