svn commit: r219815 - head/sbin/hastd

Pawel Jakub Dawidek pjd at FreeBSD.org
Mon Mar 21 08:36:50 UTC 2011


Author: pjd
Date: Mon Mar 21 08:36:50 2011
New Revision: 219815
URL: http://svn.freebsd.org/changeset/base/219815

Log:
  Add snprlcat() and vsnprlcat() - the functions I'm always missing.
  They work as a combination of snprintf(3) and strlcat(3) - the caller
  can append a string build based on the given format.
  
  MFC after:	1 week

Modified:
  head/sbin/hastd/subr.c
  head/sbin/hastd/subr.h

Modified: head/sbin/hastd/subr.c
==============================================================================
--- head/sbin/hastd/subr.c	Mon Mar 21 08:33:58 2011	(r219814)
+++ head/sbin/hastd/subr.c	Mon Mar 21 08:36:50 2011	(r219815)
@@ -38,6 +38,9 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <fcntl.h>
 #include <pwd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <pjdlog.h>
@@ -46,6 +49,27 @@ __FBSDID("$FreeBSD$");
 #include "subr.h"
 
 int
+vsnprlcat(char *str, size_t size, const char *fmt, va_list ap)
+{
+	size_t len;
+
+	len = strlen(str);
+	return (vsnprintf(str + len, size - len, fmt, ap));
+}
+
+int
+snprlcat(char *str, size_t size, const char *fmt, ...)
+{
+	va_list ap;
+	int result;
+
+	va_start(ap, fmt);
+	result = vsnprlcat(str, size, fmt, ap);
+	va_end(ap);
+	return (result);
+}
+
+int
 provinfo(struct hast_resource *res, bool dowrite)
 {
 	struct stat sb;

Modified: head/sbin/hastd/subr.h
==============================================================================
--- head/sbin/hastd/subr.h	Mon Mar 21 08:33:58 2011	(r219814)
+++ head/sbin/hastd/subr.h	Mon Mar 21 08:36:50 2011	(r219815)
@@ -45,6 +45,9 @@
 	errno = _rerrno;						\
 } while (0)
 
+int vsnprlcat(char *str, size_t size, const char *fmt, va_list ap);
+int snprlcat(char *str, size_t size, const char *fmt, ...);
+
 int provinfo(struct hast_resource *res, bool dowrite);
 const char *role2str(int role);
 int drop_privs(void);


More information about the svn-src-all mailing list