diff options
author | pjd <pjd@FreeBSD.org> | 2011-03-21 08:36:50 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-03-21 08:36:50 +0000 |
commit | 895e0371a1b3bfa3af33880e3c4eb133ec226102 (patch) | |
tree | ada90647abce88182f6aecb563dfef439c64f23a /sbin | |
parent | 5b7b8f48e306ee5dc231b9cd7efa85ee92200864 (diff) | |
download | FreeBSD-src-895e0371a1b3bfa3af33880e3c4eb133ec226102.zip FreeBSD-src-895e0371a1b3bfa3af33880e3c4eb133ec226102.tar.gz |
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
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/hastd/subr.c | 24 | ||||
-rw-r--r-- | sbin/hastd/subr.h | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/sbin/hastd/subr.c b/sbin/hastd/subr.c index 24d6dd5..213dcd2 100644 --- a/sbin/hastd/subr.c +++ b/sbin/hastd/subr.c @@ -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; diff --git a/sbin/hastd/subr.h b/sbin/hastd/subr.h index 913d2a4..0b9b555 100644 --- a/sbin/hastd/subr.h +++ b/sbin/hastd/subr.h @@ -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); |