]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - linux/string.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / linux / string.c
index fd2797eaf7739319543d1c2ac3c4be7a533d1513..a32a8995ddc46cb611490122bb43b60a007b0419 100644 (file)
 
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 #include <string.h>
 
+#include <linux/bug.h>
 #include <linux/compiler.h>
 #include <linux/string.h>
 
@@ -62,6 +64,31 @@ size_t strlcpy(char *dest, const char *src, size_t size)
        return ret;
 }
 
+ssize_t strscpy(char *dest, const char *src, size_t count)
+{
+       long res = 0;
+
+       if (count == 0 || WARN_ON_ONCE(count > INT_MAX))
+               return -E2BIG;
+
+       while (count) {
+               char c;
+
+               c = src[res];
+               dest[res] = c;
+               if (!c)
+                       return res;
+               res++;
+               count--;
+       }
+
+       /* Hit buffer length without finding a NUL; force NUL-termination. */
+       if (res)
+               dest[res-1] = '\0';
+
+       return -E2BIG;
+}
+
 void memzero_explicit(void *s, size_t count)
 {
        memset(s, 0, count);