On 07/05/2017 12:57 AM, Robert Foss wrote:
Add local strlcpy implementation.

Signed-off-by: Robert Foss <robert.f...@collabora.com>
---
Changes since v5:
   Actually include changes from v5 in patch

Changes since v4:
   Gustaw Smolarczyk <wielkie...@gmail.com>
    - Make util_strlcpy have the same behaviour as strlcpy

Changes since v3:
   Matt Turner <matts...@gmail.com>
    - Change name of util_strncpy to util_strlcpy

Changes since v2:
   Brian Paul <bri...@vmware.com>
     - 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..bbabcbc7cb 100644
--- a/src/util/u_string.h
+++ b/src/util/u_string.h
@@ -48,6 +48,15 @@
  extern "C" {
  #endif

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

This effectively walks over the source string twice. I'd suggest just using your own loop.

-Brian

+
  #ifdef _GNU_SOURCE

  #define util_strchrnul strchrnul


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to