Merge tag 'efi-2020-07-rc4' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / lib / string.c
index e94021c4680a118aed754662eb2bf2f0b2e50d4a..ae7835f600d973833d7dff62e687bd5128d7a321 100644 (file)
@@ -15,6 +15,7 @@
  *    reentrant and should be faster). Use only strsep() in new code, please.
  */
 
+#include <config.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
@@ -230,6 +231,14 @@ char * strchr(const char * s, int c)
 }
 #endif
 
+const char *strchrnul(const char *s, int c)
+{
+       for (; *s != (char)c; ++s)
+               if (*s == '\0')
+                       break;
+       return s;
+}
+
 #ifndef __HAVE_ARCH_STRRCHR
 /**
  * strrchr - Find the last occurrence of a character in a string
@@ -278,6 +287,30 @@ size_t strnlen(const char * s, size_t count)
 }
 #endif
 
+#ifndef __HAVE_ARCH_STRCSPN
+/**
+ * strcspn - Calculate the length of the initial substring of @s which does
+ * not contain letters in @reject
+ * @s: The string to be searched
+ * @reject: The string to avoid
+ */
+size_t strcspn(const char *s, const char *reject)
+{
+       const char *p;
+       const char *r;
+       size_t count = 0;
+
+       for (p = s; *p != '\0'; ++p) {
+               for (r = reject; *r != '\0'; ++r) {
+                       if (*p == *r)
+                               return count;
+               }
+               ++count;
+       }
+       return count;
+}
+#endif
+
 #ifndef __HAVE_ARCH_STRDUP
 char * strdup(const char *s)
 {
@@ -291,6 +324,29 @@ char * strdup(const char *s)
        strcpy (new, s);
        return new;
 }
+
+char * strndup(const char *s, size_t n)
+{
+       size_t len;
+       char *new;
+
+       if (s == NULL)
+               return NULL;
+
+       len = strlen(s);
+
+       if (n < len)
+               len = n;
+
+       new = malloc(len + 1);
+       if (new == NULL)
+               return NULL;
+
+       strncpy(new, s, len);
+       new[len] = '\0';
+
+       return new;
+}
 #endif
 
 #ifndef __HAVE_ARCH_STRSPN