4 lip 2017 14:25 "Robert Foss" <[email protected]> napisaƂ(a):

Add local strlcpy implementation.

Signed-off-by: Robert Foss <[email protected]>
---
Changes since v3:
  Matt Turner <[email protected]>
   - Change name of util_strncpy to util_strlcpy

Changes since v2:
  Brian Paul <[email protected]>
    - Patch added

 src/util/u_string.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/util/u_string.h b/src/util/u_string.h
index e88e13f42c..77014bc744 100644
--- a/src/util/u_string.h
+++ b/src/util/u_string.h
@@ -48,6 +48,15 @@
 extern "C" {
 #endif

+static inline char*
+util_strlcpy(char *dst, const char *src, size_t n)
+{
+   strncpy(dst, src, n);
+   dst[n-1] = '\0';
+
+   return dst;
+}


The original strlcpy returns the amount of characters of the source string
which can be used in order to know whether the truncation happened or not.

It's probably unnecessary right know but might be useful in the future.

Gustaw

+
 #ifdef _GNU_SOURCE

 #define util_strchrnul strchrnul
--
2.11.0
_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to