Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd/drm2/include/linux Implement strscpy.
details: https://anonhg.NetBSD.org/src/rev/5bd5dbb62524
branches: trunk
changeset: 1027813:5bd5dbb62524
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Dec 19 00:48:30 2021 +0000
description:
Implement strscpy.
diffstat:
sys/external/bsd/drm2/include/linux/string.h | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
diffs (43 lines):
diff -r c2512197522c -r 5bd5dbb62524 sys/external/bsd/drm2/include/linux/string.h
--- a/sys/external/bsd/drm2/include/linux/string.h Sun Dec 19 00:48:23 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/string.h Sun Dec 19 00:48:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: string.h,v 1.5 2018/08/27 06:49:23 riastradh Exp $ */
+/* $NetBSD: string.h,v 1.6 2021/12/19 00:48:30 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,6 +34,7 @@
#include <sys/types.h>
#include <sys/cdefs.h>
+#include <sys/errno.h>
#include <sys/null.h>
#include <linux/slab.h>
@@ -93,4 +94,25 @@
return kstrndup(src, strlen(src), gfp);
}
+static inline ssize_t
+strscpy(char *dst, const char *src, size_t dstsize)
+{
+ size_t n = dstsize;
+
+ /* If no space for a NUL terminator, fail. */
+ if (n == 0)
+ return -E2BIG;
+
+ /* Copy until we get a NUL terminator or the end of the buffer. */
+ while ((*dst++ = *src++) != '\0') {
+ if (__predict_false(--n == 0)) {
+ dst[-1] = '\0'; /* NUL-terminate */
+ return -E2BIG;
+ }
+ }
+
+ /* Return the number of bytes copied, excluding NUL. */
+ return dstsize - n;
+}
+
#endif /* _LINUX_STRING_H_ */
Home |
Main Index |
Thread Index |
Old Index