Date: Mon, 21 Mar 2011 08:36:50 +0000 (UTC) From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r219815 - head/sbin/hastd Message-ID: <201103210836.p2L8aoee004893@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103210836.p2L8aoee004893>