mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-12 05:41:36 +00:00
Let memcmp correspond to the C standard (fix #628)
By now, the memcmp implementation of Genode's basic string utilities just returned whether two memory blocks are equal or differ. It gave no hint which block is greater, or lesser than the other one. This isn't the behaviour anticipated by implementations that rely on the C standard memcmp, e.g. GCC's libsupc++, or the nic_bridge's AVL tree implementation.
This commit is contained in:
parent
b4980e8b9f
commit
04b8418b54
@ -154,19 +154,18 @@ namespace Genode {
|
||||
/**
|
||||
* Compare memory blocks
|
||||
*
|
||||
* \retval 0 memory blocks are equal
|
||||
* \retval 1 memory blocks differ
|
||||
*
|
||||
* NOTE: This function is not fully compatible to the C standard.
|
||||
* \retval 0 memory blocks are equal
|
||||
* \retval <0 first memory block is less than second one
|
||||
* \retval >0 first memory block is greater than second one
|
||||
*/
|
||||
inline int memcmp(const void *p0, const void *p1, size_t size)
|
||||
{
|
||||
char *c0 = (char *)p0;
|
||||
char *c1 = (char *)p1;
|
||||
const unsigned char *c0 = (const unsigned char *)p0;
|
||||
const unsigned char *c1 = (const unsigned char *)p1;
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < size; i++)
|
||||
if (c0[i] != c1[i]) return 1;
|
||||
if (c0[i] != c1[i]) return c0[i] - c1[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user