/* * Append a string to <buf>, formatted according to <fmt> and the subsequent parameters. */ Buffer *bufAddF(Buffer *buf, const char *fmt, ...) { va_list ap; va_start(ap, fmt); bufAddV(buf, fmt, ap); va_end(ap); return buf; }
/* * Log <fmt> and the subsequent parameters through <logger>, *without* any * prefixes. Useful to continue a previous log message. */ void logAppend(Logger *logger, const char *fmt, ...) { va_list ap; pthread_mutex_lock(&logger->access); bufClear(&logger->scratch); va_start(ap, fmt); bufAddV(&logger->scratch, fmt, ap); va_end(ap); log_output(logger); pthread_mutex_unlock(&logger->access); }
/* * This function assists in building textual lists of the form "Tom, Dick and Harry". Call it three * times with the arguments "Tom", "Dick" and "Harry". Set sep1 to ", " and sep2 to " and ". Set * is_first to TRUE when passing in "Tom", set is_last to TRUE when passing in "Harry", set them * both to FALSE for "Dick". Returns the same pointer to <buf> that was passed in. */ Buffer *bufList(Buffer *buf, const char *sep1, const char *sep2, int is_first, int is_last, const char *fmt, ...) { va_list ap; if (!is_first) { if (is_last) bufAddF(buf, "%s", sep2); else bufAddF(buf, "%s", sep1); } va_start(ap, fmt); bufAddV(buf, fmt, ap); va_end(ap); return buf; }
/* * Send out a logging message using <fmt> and the subsequent parameters through * <logger>. <file>, <line> and <func> are filled in by the logWrite macro, * which should be used to call this function. */ void _logWrite(Logger *logger, const char *file, int line, const char *func, const char *fmt, ...) { va_list ap; pthread_mutex_lock(&logger->access); bufClear(&logger->scratch); log_write_prefixes(logger, file, line, func); va_start(ap, fmt); bufAddV(&logger->scratch, fmt, ap); va_end(ap); log_output(logger); pthread_mutex_unlock(&logger->access); }
/* * Replace <buf> with a string formatted according to <fmt> and the subsequent parameters contained * in <ap>. */ Buffer *bufSetV(Buffer *buf, const char *fmt, va_list ap) { bufClear(buf); return bufAddV(buf, fmt, ap); }