Name n3617, alx-0024r1 - add memeq(), wmemeq() Principles - Codify existing practice to address evident deficiencies. - Enable secure programming Category Standardize common APIs Author Alejandro Colomar Cc: Yair Lenga Cc: Joseph Myers Cc: Martin Uecker History r0 (2025-06-13): - Initial draft. r1 (2025-06-26; n3617): - Fix title. - Fix type of parameters. Rationale See the rationale for streq() in alx-0024 for why this wrapper is better than using memcmp(3) directly. Some projects use mem*() APIs instead of str*() APIs for performance reasons. To enable those projects to write better code, we should add a memeq() API, just like there's a proposal for streq(). Prior art Some projects define this API, either as a macro or as a function. Here's an example implementation: bool memeq(const void *m1, const void *m2, size_t n) { return memcmp(m1, m2, n) == 0; } Proposed wording Based on N3550. 7.28.4 String handling :: Comparison functions ## New section after 7.28.4.2 ("The memcmp function"): +7.28.4.2+1 The memeq function + +Synopsis +1 #include + bool memeq(const void *m1, const void *m2, size_t n); + +Description +2 The memeq function + is equivalent to memcmp, + except for the return value. + +Returns +3 The memeq function returns true + if and only if all bytes are equal. 7.33.4.5 Wide string comparison functions ## New section after 7.33.4.5.6 ("The wmemcmp function"): +7.33.4.5.6+1 The wmemeq function + +Synopsis +1 #include + bool wmemeq(const wchar_t *m1, const wchar_t *m2, size_t n); + +Description +2 The wmemeq function + is equivalent to + memeq, + except that it handles wide characters.