[Cluster-devel] [RFC 06/11] lib: Move strcmp_prefix into string.c
Andreas Gruenbacher
andreas.gruenbacher at gmail.com
Thu Aug 20 18:19:53 UTC 2015
Move strcmp_prefix from fs/xattr.c into lib/string.h to make it available
elsewhere; export it to modules.
Signed-off-by: Andreas Gruenbacher <agruenba at redhat.com>
---
fs/xattr.c | 11 -----------
include/linux/string.h | 1 +
lib/string.c | 16 ++++++++++++++++
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/fs/xattr.c b/fs/xattr.c
index efa16ce..9584808 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -663,17 +663,6 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
return error;
}
-
-static const char *
-strcmp_prefix(const char *a, const char *a_prefix)
-{
- while (*a_prefix && *a == *a_prefix) {
- a++;
- a_prefix++;
- }
- return *a_prefix ? NULL : a;
-}
-
/*
* In order to implement different sets of xattr operations for each xattr
* prefix with the generic xattr API, a filesystem should create a
diff --git a/include/linux/string.h b/include/linux/string.h
index a8d90db..edc155d 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -37,6 +37,7 @@ extern size_t strlcat(char *, const char *, __kernel_size_t);
#ifndef __HAVE_ARCH_STRCMP
extern int strcmp(const char *,const char *);
#endif
+extern const char *strcmp_prefix(const char *, const char *);
#ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
diff --git a/lib/string.c b/lib/string.c
index 13d1e84..697572d 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -246,6 +246,22 @@ int strcmp(const char *cs, const char *ct)
EXPORT_SYMBOL(strcmp);
#endif
+/**
+ * strcmp_prefix - check string for given prefix
+ *
+ * Returns @str + strlen(@prefix) if @str has the given @prefix, and NULL
+ * otherwise.
+ */
+const char *strcmp_prefix(const char *str, const char *prefix)
+{
+ while (*prefix && *str == *prefix) {
+ str++;
+ prefix++;
+ }
+ return *prefix ? NULL : str;
+}
+EXPORT_SYMBOL(strcmp_prefix);
+
#ifndef __HAVE_ARCH_STRNCMP
/**
* strncmp - Compare two length-limited strings
--
2.4.3
More information about the Cluster-devel
mailing list