summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backport/backport-include/linux/string.h4
-rw-r--r--backport/compat/backport-4.6.c26
2 files changed, 30 insertions, 0 deletions
diff --git a/backport/backport-include/linux/string.h b/backport/backport-include/linux/string.h
index 4b35eb9f..2bfdf747 100644
--- a/backport/backport-include/linux/string.h
+++ b/backport/backport-include/linux/string.h
@@ -33,4 +33,8 @@ ssize_t strscpy(char *dest, const char *src, size_t count);
char *strreplace(char *s, char old, char new);
#endif
+#if LINUX_VERSION_IS_LESS(4,6,0)
+int match_string(const char * const *array, size_t n, const char *string);
+#endif /* LINUX_VERSION_IS_LESS(4,5,0) */
+
#endif /* __BACKPORT_LINUX_STRING_H */
diff --git a/backport/compat/backport-4.6.c b/backport/compat/backport-4.6.c
index 54ff669d..8d0ecf56 100644
--- a/backport/compat/backport-4.6.c
+++ b/backport/compat/backport-4.6.c
@@ -75,3 +75,29 @@ int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
return kstrtobool(buf, res);
}
EXPORT_SYMBOL_GPL(kstrtobool_from_user);
+
+/**
+ * match_string - matches given string in an array
+ * @array: array of strings
+ * @n: number of strings in the array or -1 for NULL terminated arrays
+ * @string: string to match with
+ *
+ * Return:
+ * index of a @string in the @array if matches, or %-EINVAL otherwise.
+ */
+int match_string(const char * const *array, size_t n, const char *string)
+{
+ int index;
+ const char *item;
+
+ for (index = 0; index < n; index++) {
+ item = array[index];
+ if (!item)
+ break;
+ if (!strcmp(item, string))
+ return index;
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL(match_string);