summaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
diff options
context:
space:
mode:
authorPetr Uzel2011-11-08 16:25:01 +0100
committerKarel Zak2011-11-08 16:25:01 +0100
commitb106d052383083b80c0dc41f1555d2661db00374 (patch)
tree1a47a77f18b6935b7c67a219617091951e236d94 /lib/strutils.c
parentlib,loopdev: add LOOP_CTL_GET_FREE support (diff)
downloadkernel-qcow2-util-linux-b106d052383083b80c0dc41f1555d2661db00374.tar.gz
kernel-qcow2-util-linux-b106d052383083b80c0dc41f1555d2661db00374.tar.xz
kernel-qcow2-util-linux-b106d052383083b80c0dc41f1555d2661db00374.zip
libmount: ignore tailing slash in netfs source paths
Addresses: https://bugzilla.novell.com/show_bug.cgi?id=728480 Signed-off-by: Petr Uzel <petr.uzel@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/strutils.c')
-rw-r--r--lib/strutils.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/strutils.c b/lib/strutils.c
index 6b2ec799e..75861607e 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -504,6 +504,38 @@ int parse_range(const char *str, int *lower, int *upper, int def)
return 0;
}
+/*
+ * Compare two strings for equality, ignoring at most one trailing
+ * slash.
+ */
+int streq_except_trailing_slash(const char *s1, const char *s2)
+{
+ int equal;
+
+ if (!s1 && !s2)
+ return 1;
+ if (!s1 || !s2)
+ return 0;
+
+ equal = !strcmp(s1, s2);
+
+ if (!equal) {
+ size_t len1 = strlen(s1);
+ size_t len2 = strlen(s2);
+
+ if (len1 && *(s1 + len1 - 1) == '/')
+ len1--;
+ if (len2 && *(s2 + len2 - 1) == '/')
+ len2--;
+ if (len1 != len2)
+ return 0;
+
+ equal = !strncmp(s1, s2, len1);
+ }
+
+ return equal;
+}
+
#ifdef TEST_PROGRAM