-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
include: util: Add memeq
and bool_memcmp
#84159
base: main
Are you sure you want to change the base?
Conversation
`memeq` compare two memory areas and their length. It returns true if they are equal, else false. `bool_memcmp` the first n bytes of two memory areas. It returns true if they are equal, else false. Signed-off-by: Théo Battrel <[email protected]>
Add two unit tests for the newly added functions `memeq` and `bool_memcmp`. Signed-off-by: Théo Battrel <[email protected]>
I don't see the benefit of adding these, sorry. |
What I mean was that I don't see any added value of introducing what basically is an alias... if (memeq(buf1, size1, buf2, size2)) { /* ... */ }
/* vs */
if (size1 == size2 && memcmp(buf1, buf2, size1) == 0) { /* ... */ } |
Tend to agree with @pdgendt, we don't want to be pushing APIs that compete with well-established controlling idioms (like the ISO C standard memcmp() in this case, but we take stuff from Linux too). |
Maybe I am missing something but that file is full of aliases... I don't see the problem with adding new ones
I struggle to understand the reasoning about APIs that compete, sorry, could you develop? And those function are just more convenient to use. Nobody is forced to use them 😅 |
I disagree. The file, in my opinion, provides common functions people tend to get wrong or inefficient implementations of.
Nobody is forced to use them, but suddenly |
Sorry but I must insist, there is an alias for
Sorry, I don't understand, what is the problem here? It will not be included in people code if they don't use it |
Those two functions are used to compare memory area.
bool_memcmp
is basicallymemcmp
but return abool
instead of anint
.memeq
compare the length of the memory area in addition to the bytes themselves.