]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: utils: Switch matches() to returning int again
authorPetr Machata <petrm@nvidia.com>
Wed, 22 Nov 2023 15:23:28 +0000 (16:23 +0100)
committerDavid Ahern <dsahern@kernel.org>
Wed, 22 Nov 2023 19:31:55 +0000 (19:31 +0000)
Since commit 1f420318bda3 ("utils: don't match empty strings as prefixes")
the function has pretended to return a boolean. But every user expects it
to return zero on success and a non-zero value on failure, like strcmp().
Even the function itself actually returns "true" to mean "no match". This
only makes sense if one considers a boolean to be a one-bit unsigned
integer with no inherent meaning, which I do not think is reasonable.

Switch the prototype back to int, and return 1 instead of true.

Cc: Matteo Croce <mcroce@redhat.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/utils.h
lib/utils.c

index f26ed822f3099bc5a6c7ca7257e7864969232e58..add55bfa3a33639224ff64c67fc03a9b5a878721 100644 (file)
@@ -198,7 +198,7 @@ int check_ifname(const char *);
 int check_altifname(const char *name);
 int get_ifname(char *, const char *);
 const char *get_ifname_rta(int ifindex, const struct rtattr *rta);
-bool matches(const char *prefix, const char *string);
+int matches(const char *prefix, const char *string);
 int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits);
 int inet_addr_match_rta(const inet_prefix *m, const struct rtattr *rta);
 
index 99ba7a2333d2d9dcb544388c04e4acf5b1a0a6e8..1fc42a9a8f040ae27fc819876c753158715a3659 100644 (file)
@@ -873,18 +873,18 @@ const char *get_ifname_rta(int ifindex, const struct rtattr *rta)
        return name;
 }
 
-/* Returns false if 'prefix' is a not empty prefix of 'string'.
+/* Returns 0 if 'prefix' is a not empty prefix of 'string', != 0 otherwise.
  */
-bool matches(const char *prefix, const char *string)
+int matches(const char *prefix, const char *string)
 {
        if (!*prefix)
-               return true;
+               return 1;
        while (*string && *prefix == *string) {
                prefix++;
                string++;
        }
 
-       return !!*prefix;
+       return *prefix;
 }
 
 int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits)