summaryrefslogtreecommitdiff
path: root/linux/string.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-10-22 13:25:25 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2022-10-22 14:41:54 -0400
commit188b6d0c8ef1c02462a744b176557c27220112c9 (patch)
treeab1f239b3bad0335e1d3fa62415bc8d845ba68be /linux/string.c
parent494421ee6e85514f90bb316d77e1dd4f7dad3420 (diff)
Update bcachefs sources to cd779e0cc5 bcachefs: Skip inode unpack/pack in bch2_extent_update()v0.23
Diffstat (limited to 'linux/string.c')
-rw-r--r--linux/string.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/linux/string.c b/linux/string.c
index fd2797ea..a32a8995 100644
--- a/linux/string.c
+++ b/linux/string.c
@@ -21,8 +21,10 @@
#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);