[systemd-devel] sd_id128_equal borked

Lennart Poettering mzerqung at 0pointer.de
Sat Feb 28 02:44:24 PST 2015


On Fri, 27.02.15 15:48, Shawn Landden (shawnlandden at gmail.com) wrote:

> _sd_pure_ static inline int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
>         return memcmp(&a, &b, 16) == 0;
> }
> 
> this should either be return memcmp(&a, &b, 16);
> or return bool

The way I see it "equal" functions are supposed to return a boolean
value, while "compare" functions should return an integer that is 0,
positive, or negative depending on equality and order. 

sd_id128_equal is an "equal" function, and should thus return a
boolean value. However, in public APIs we try to avoid C99isms or
GNUisms (with a few extensions), and stick to C89. Since C89 did not
know the "bool" type we hence use "int" for booleans instead, how it
is customary in C89 code.

THe code is hence correct the way it is.

I have now updated CODING_STYLE to clarify that we use C99 bool only
in internal code, and use "int" instead on external APIs in
src/systemd/sd-*.h.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list