Example #1
0
/**
 * Set process title, for the ps(1) command to report an updated title.
 *
 * The title is set from the executable's name, followed by the result of a
 * printf(3) style expansion of the arguments as specified by the fmt argument.
 *
 * If the fmt argument begins with a ``-'' character, the executable's name
 * is skipped.
 *
 * If fmt is NULL, the original process title is restored.
 */
void
setproctitle(const char *fmt, ...)
{
	va_list args;
	char *start;
	size_t len;
	buf_t *b, bs;

	start = progname_args_start();
	len = progname_args_size();

	if (0 == len)
		return;

	b = buf_init(&bs, start, len);
	memset(start, 0, len);

	va_start(args, fmt);

	if (NULL == fmt) {
		buf_printf(b, "%s", progstart_arg(0));
	} else if ('-' == *fmt) {
		buf_vprintf(b, fmt + 1, args);
	} else {
		buf_printf(b, "%s ", getprogname());
		buf_vcatf(b, fmt, args);
	}

	va_end(args);
}
Example #2
0
Buf *buf_sprintf(const char *format, ...) {
    va_list ap;
    va_start(ap, format);
    Buf *result = buf_vprintf(format, ap);
    va_end(ap);
    return result;
}
Example #3
0
void buf_printf(struct buf *buf, const char *format, ...) {
  va_list args;
  va_start(args, format);
  buf_vprintf(buf, format, args);
  va_end(args);
}