mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 06:25:37 +03:00
fundamental: make strverscmp_improved() return -1/0/+1 in all cases
We would return the result of strcmp(), i.e. some positive/negative value. Now that we want to make this a documented interface for other people to implement, let's make the implementation more contstrained, even if we ourselves don't care about whether the specific values.
This commit is contained in:
parent
e77a55c599
commit
dbf43adce2
@ -126,7 +126,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
|
||||
*/
|
||||
|
||||
if (isempty(a) || isempty(b))
|
||||
return strcmp_ptr(a, b);
|
||||
return CMP(strcmp_ptr(a, b), 0);
|
||||
|
||||
for (;;) {
|
||||
const sd_char *aa, *bb;
|
||||
@ -208,7 +208,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
|
||||
return r;
|
||||
|
||||
/* Then, compare them as strings. */
|
||||
r = strncmp(a, b, aa - a);
|
||||
r = CMP(strncmp(a, b, aa - a), 0);
|
||||
if (r != 0)
|
||||
return r;
|
||||
} else {
|
||||
@ -219,7 +219,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
|
||||
;
|
||||
|
||||
/* Note that the segments are usually not NUL-terminated. */
|
||||
r = strncmp(a, b, MIN(aa - a, bb - b));
|
||||
r = CMP(strncmp(a, b, MIN(aa - a, bb - b)), 0);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user