Skip to content

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)

Usage examples (Cross-references)
    #include <Misra/Std/Log.h>
    
    i32 MemCompare(const void *p1, const void *p2, size n) {
        if (!p1 || !p2) {
            LOG_FATAL("Invalid arguments");
    
            // Compare the substring
            if (MemCompare(haystack + pos, needle, needle_len) == 0) {
                return (char *)(haystack + pos);
            }
    
    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;
    }
    
    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;
    }
    
        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);
    
        min = a->length < b->length ? a->length : b->length;
        cmp = MemCompare(a->data, b->data, min);
    
        if (cmp != 0) {
Last updated on