#include "config.h"
#endif
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern char *optarg;
extern int optind;
+/* ssnprintf returns zero on success, one if truncation occurred
+ and a negative integer onerror. */
+static int _ssnprintf(char *str, size_t sz, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+
+ int ret = vsnprintf(str, sz, format, ap);
+
+ va_end(ap);
+
+ if (ret < 0) {
+ return ret;
+ }
+ return (size_t)ret >= sz;
+} /* int _ssnprintf */
+
__attribute__((noreturn)) static void exit_usage(const char *name, int status) {
fprintf(
(status == 0) ? stdout : stderr,
}
hostname[sizeof(hostname) - 1] = '\0';
- snprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value);
+ _ssnprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value);
ident_str[sizeof(ident_str) - 1] = '\0';
} else {
strncpy(ident_str, value, sizeof(ident_str));
switch (opt) {
case 's':
- snprintf(address, sizeof(address), "unix:%s", optarg);
+ _ssnprintf(address, sizeof(address), "unix:%s", optarg);
address[sizeof(address) - 1] = '\0';
break;
case 'h':