summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2023-01-04 15:48:01 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2023-01-04 15:48:01 +0000
commit86bffe989746a3ca05738221a43ba7c52c486391 (patch)
tree6fe225c526d013a0f28c88a4cba2e8e10629f2b6
parent2ec49dd34f568c420da251746a4e3701c963b55d (diff)
Implement strscpy() and implement strscpy_pad() on top of that. Fixes the
return value in case of truncation. ok jsg@
-rw-r--r--sys/dev/pci/drm/include/linux/string.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/sys/dev/pci/drm/include/linux/string.h b/sys/dev/pci/drm/include/linux/string.h
index b19c465e2a0..f76ddf6f680 100644
--- a/sys/dev/pci/drm/include/linux/string.h
+++ b/sys/dev/pci/drm/include/linux/string.h
@@ -81,17 +81,21 @@ match_string(const char * const *array, size_t n, const char *str)
return -EINVAL;
}
-/* returns chars written excluding NUL */
static inline ssize_t
-strscpy_pad(char *dst, const char *src, size_t dstsize)
+strscpy(char *dst, const char *src, size_t dstsize)
{
ssize_t r;
- memset(dst, 0, dstsize);
r = strlcpy(dst, src, dstsize);
- /* truncation */
- if (r >= dstsize)
- r = dstsize - 1;
+ if (dstsize == 0 || r >= dstsize)
+ return -E2BIG;
return r;
}
+static inline ssize_t
+strscpy_pad(char *dst, const char *src, size_t dstsize)
+{
+ memset(dst, 0, dstsize);
+ return strscpy(dst, src, dstsize);
+}
+
#endif