lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Fri,  9 Feb 2024 04:36:18 -0500
From: Denis Kirjanov <kirjanov@...il.com>
To: stephen@...workplumber.org,
	dsahern@...nel.org
Cc: netdev@...r.kernel.org,
	Denis Kirjanov <dkirjanov@...e.de>
Subject: [PATCH iproute2 1/2] lib: utils: introduce scnprintf

The function is similar to the standard snprintf but
returns the number of characters actually written to @buf
argument excluding the trailing '\0'

Signed-off-by: Denis Kirjanov <dkirjanov@...e.de>
---
 include/utils.h |  1 +
 lib/utils.c     | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/include/utils.h b/include/utils.h
index 9ba129b8..5b65edc5 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -393,4 +393,5 @@ int proto_a2n(unsigned short *id, const char *buf,
 const char *proto_n2a(unsigned short id, char *buf, int len,
 		      const struct proto *proto_tb, size_t tb_len);
 
+int scnprintf(char * buf, size_t size, const char * fmt, ...);
 #endif /* __UTILS_H__ */
diff --git a/lib/utils.c b/lib/utils.c
index 6c1c1a8d..752da66f 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -7,6 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <math.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -2003,3 +2004,16 @@ int proto_a2n(unsigned short *id, const char *buf,
 
 	return 0;
 }
+
+int scnprintf(char * buf, size_t size, const char * fmt, ...)
+{
+       ssize_t ssize = size;
+       va_list args;
+       int i;
+
+       va_start(args, fmt);
+       i = vsnprintf(buf, size, fmt, args);
+       va_end(args);
+
+       return (i >= ssize) ? (ssize - 1) : i;
+}
-- 
2.30.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ