Whamcloud - gitweb
LU-6245 libcfs: create userland and kernel string operations
[fs/lustre-release.git] / libcfs / libcfs / libcfs_string.c
index ae6a9e3..ebe91ac 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -69,26 +69,6 @@ char *cfs_strrstr(const char *haystack, const char *needle)
 }
 EXPORT_SYMBOL(cfs_strrstr);
 
-/* non-0 = don't match */
-int cfs_strncasecmp(const char *s1, const char *s2, size_t n)
-{
-        if (s1 == NULL || s2 == NULL)
-                return 1;
-
-        if (n == 0)
-                return 0;
-
-        while (n-- != 0 && tolower(*s1) == tolower(*s2)) {
-                if (n == 0 || *s1 == '\0' || *s2 == '\0')
-                        break;
-                s1++;
-                s2++;
-        }
-
-        return tolower(*(unsigned char *)s1) - tolower(*(unsigned char *)s2);
-}
-EXPORT_SYMBOL(cfs_strncasecmp);
-
 /* Convert a text string to a bitmask */
 int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
                  int *oldmask, int minmask, int allmask)
@@ -129,7 +109,7 @@ int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
                         debugstr = bit2str(i);
                         if (debugstr != NULL &&
                             strlen(debugstr) == len &&
-                            cfs_strncasecmp(str, debugstr, len) == 0) {
+                           strncasecmp(str, debugstr, len) == 0) {
                                 if (op == '-')
                                         newmask &= ~(1 << i);
                                 else
@@ -139,7 +119,7 @@ int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
                         }
                 }
                 if (!found && len == 3 &&
-                    (cfs_strncasecmp(str, "ALL", len) == 0)) {
+                   (strncasecmp(str, "ALL", len) == 0)) {
                         if (op == '-')
                                 newmask = minmask;
                         else
@@ -159,24 +139,6 @@ int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
 }
 EXPORT_SYMBOL(cfs_str2mask);
 
-/* Duplicate a string in a platform-independent way */
-char *cfs_strdup(const char *str, u_int32_t flags)
-{
-        size_t lenz; /* length of str + zero byte */
-        char *dup_str;
-
-        lenz = strlen(str) + 1;
-
-       dup_str = kmalloc(lenz, flags);
-        if (dup_str == NULL)
-                return NULL;
-
-        memcpy(dup_str, str, lenz);
-
-        return dup_str;
-}
-EXPORT_SYMBOL(cfs_strdup);
-
 /**
  * cfs_{v}snprintf() return the actual size that is printed rather than
  * the size that would be printed in standard functions.
@@ -240,12 +202,12 @@ cfs_trimwhite(char *str)
 {
        char *end;
 
-       while (cfs_iswhite(*str))
+       while (isspace(*str))
                str++;
 
        end = str + strlen(str);
        while (end > str) {
-               if (!cfs_iswhite(end[-1]))
+               if (!isspace(end[-1]))
                        break;
                end--;
        }
@@ -275,7 +237,7 @@ cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res)
 
        /* skip leading white spaces */
        while (next->ls_len) {
-               if (!cfs_iswhite(*next->ls_str))
+               if (!isspace(*next->ls_str))
                        break;
                next->ls_str++;
                next->ls_len--;
@@ -302,7 +264,7 @@ cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res)
 
        /* skip ending whitespaces */
        while (--end != res->ls_str) {
-               if (!cfs_iswhite(*end))
+               if (!isspace(*end))
                        break;
        }
 
@@ -326,13 +288,12 @@ cfs_str2num_check(char *str, int nob, unsigned *num,
 {
        char    *endp;
 
-       str = cfs_trimwhite(str);
-       *num = strtoul(str, &endp, 0);
+       *num = simple_strtoul(str, &endp, 0);
        if (endp == str)
                return 0;
 
        for (; endp < str + nob; endp++) {
-               if (!cfs_iswhite(*endp))
+               if (!isspace(*endp))
                        return 0;
        }
 
@@ -566,7 +527,7 @@ cfs_expr_list_free(struct cfs_expr_list *expr_list)
                struct cfs_range_expr *expr;
 
                expr = list_entry(expr_list->el_exprs.next,
-                                     struct cfs_range_expr, re_link),
+                                     struct cfs_range_expr, re_link);
                list_del(&expr->re_link);
                LIBCFS_FREE(expr, sizeof(*expr));
        }
@@ -720,10 +681,3 @@ cfs_ip_addr_match(__u32 addr, struct list_head *list)
        return i == 4;
 }
 EXPORT_SYMBOL(cfs_ip_addr_match);
-
-void
-cfs_ip_addr_free(struct list_head *list)
-{
-       cfs_expr_list_free_list(list);
-}
-EXPORT_SYMBOL(cfs_ip_addr_free);