+/*
+ * append_format
+ *
+ * inputs - pointer to buffer
+ * - size of buffer
+ * - pointer to position
+ * - format string
+ * - arguments for format
+ * output - NONE
+ * side effects - position incremented, possibly beyond size of buffer
+ * this allows detecting overflow
+ */
+static void
+append_format(char *buf, size_t bufsize, size_t *pos, const char *fmt, ...)
+{
+ size_t max, result;
+ va_list ap;
+
+ max = *pos >= bufsize ? 0 : bufsize - *pos;
+ va_start(ap, fmt);
+ result = rb_vsnprintf(buf + *pos, bufsize - *pos, fmt, ap);
+ va_end(ap);
+ *pos += result;
+}
+