naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0117-utils-Implement-strlcpy-and-strlcat.patch

36cfb7
From 3bcdea42e7402e79a914fe3cbefdcc1caa89464c Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 20:08:08 +0200
36cfb7
Subject: [PATCH] utils: Implement strlcpy() and strlcat()
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit 8d15e012a3227
36cfb7
36cfb7
commit 8d15e012a3227d79295cd95582bb6d8a6f0bdc92
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Fri Sep 1 18:52:51 2017 +0200
36cfb7
36cfb7
    utils: Implement strlcpy() and strlcat()
36cfb7
36cfb7
    By making use of strncpy(), both implementations are really simple so
36cfb7
    there is no need to add libbsd as additional dependency.
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 include/utils.h |  3 +++
36cfb7
 lib/utils.c     | 19 +++++++++++++++++++
36cfb7
 2 files changed, 22 insertions(+)
36cfb7
36cfb7
diff --git a/include/utils.h b/include/utils.h
36cfb7
index d707a9dacdb85..d596a6fc10574 100644
36cfb7
--- a/include/utils.h
36cfb7
+++ b/include/utils.h
36cfb7
@@ -264,4 +264,7 @@ int make_path(const char *path, mode_t mode);
36cfb7
 char *find_cgroup2_mount(void);
36cfb7
 int get_command_name(const char *pid, char *comm, size_t len);
36cfb7
 
36cfb7
+size_t strlcpy(char *dst, const char *src, size_t size);
36cfb7
+size_t strlcat(char *dst, const char *src, size_t size);
36cfb7
+
36cfb7
 #endif /* __UTILS_H__ */
36cfb7
diff --git a/lib/utils.c b/lib/utils.c
36cfb7
index fc9c575ba0c7d..c9ba2f332c2a7 100644
36cfb7
--- a/lib/utils.c
36cfb7
+++ b/lib/utils.c
36cfb7
@@ -1228,3 +1228,22 @@ int get_real_family(int rtm_type, int rtm_family)
36cfb7
 
36cfb7
 	return rtm_family;
36cfb7
 }
36cfb7
+
36cfb7
+size_t strlcpy(char *dst, const char *src, size_t size)
36cfb7
+{
36cfb7
+	if (size) {
36cfb7
+		strncpy(dst, src, size - 1);
36cfb7
+		dst[size - 1] = '\0';
36cfb7
+	}
36cfb7
+	return strlen(src);
36cfb7
+}
36cfb7
+
36cfb7
+size_t strlcat(char *dst, const char *src, size_t size)
36cfb7
+{
36cfb7
+	size_t dlen = strlen(dst);
36cfb7
+
36cfb7
+	if (dlen > size)
36cfb7
+		return dlen + strlen(src);
36cfb7
+
36cfb7
+	return dlen + strlcpy(dst + dlen, src, size - dlen);
36cfb7
+}
36cfb7
-- 
e138d9
2.21.0
36cfb7