当前位置: 首页>>代码示例>>C++>>正文


C++ xvasprintf函数代码示例

本文整理汇总了C++中xvasprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ xvasprintf函数的具体用法?C++ xvasprintf怎么用?C++ xvasprintf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xvasprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: filter_ansi

static void filter_ansi(FILE *file, const char *fmt, va_list args)
{
	_cleanup_free_ char *str = NULL;
	size_t len, i, j;

	if (color_mode == COLOR_MODE_ALWAYS ||
	    (color_mode == COLOR_MODE_AUTO && isatty(fileno(file)))) {
		vfprintf(file, fmt, args);
		return;
	}

	len = xvasprintf(&str, fmt, args);

	for (i = 0; i < len - 2; ++i) {
		if (str[i] == '\x1b' && str[i + 1] == '[') {
			str[i] = str[i + 1] = '\0';
			for (j = i + 2; j < len; ++j) {
				if (isalpha(str[j]))
					break;
				str[j] = '\0';
			}
			str[j] = '\0';
		}
	}
	for (i = 0; i < len; i = j) {
		fputs(&str[i], file);
		for (j = i + strlen(&str[i]); j < len; ++j) {
			if (str[j] != '\0')
				break;
		}
	}
}
开发者ID:Evalle,项目名称:lastpass-cli,代码行数:32,代码来源:terminal.c

示例2: screen_write_cstrlen

/* Calculate string length, with embedded formatting. */
size_t
screen_write_cstrlen(const char *fmt, ...)
{
	va_list	ap;
	char   *msg, *msg2, *ptr, *ptr2;
	size_t	size;

	va_start(ap, fmt);
	xvasprintf(&msg, fmt, ap);
	va_end(ap);
	msg2 = xmalloc(strlen(msg) + 1);

	ptr = msg;
	ptr2 = msg2;
	while (*ptr != '\0') {
		if (ptr[0] == '#' && ptr[1] == '[') {
			while (*ptr != ']' && *ptr != '\0')
				ptr++;
			if (*ptr == ']')
				ptr++;
			continue;
		}
		*ptr2++ = *ptr++;
	}
	*ptr2 = '\0';

	size = screen_write_strlen("%s", msg2);

	free(msg);
	free(msg2);

	return (size);
}
开发者ID:CraZySacX,项目名称:tmux,代码行数:34,代码来源:screen-write.c

示例3: screen_write_strlen

/* Calculate string length. */
size_t printflike2
screen_write_strlen(int utf8flag, const char *fmt, ...)
{
	va_list			ap;
	char   	       	       *msg;
	struct utf8_data	utf8data;
	u_char 	      	       *ptr;
	size_t			left, size = 0;

	va_start(ap, fmt);
	xvasprintf(&msg, fmt, ap);
	va_end(ap);

	ptr = msg;
	while (*ptr != '\0') {
		if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
			ptr++;

			left = strlen(ptr);
			if (left < utf8data.size - 1)
				break;
			while (utf8_append(&utf8data, *ptr))
				ptr++;
			ptr++;

			size += utf8data.width;
		} else {
			size++;
			ptr++;
		}
	}

	free(msg);
	return (size);
}
开发者ID:HonestQiao,项目名称:tmux,代码行数:36,代码来源:screen-write.c

示例4: xvasprintf_wrapper

xvasprintf_wrapper(char **strp, const char *format, ...)
{
    va_list args;

    va_start(args, format);
    xvasprintf(strp, format, args);
    va_end(args);
}
开发者ID:rra,项目名称:krb5-strength,代码行数:8,代码来源:xmalloc.c

示例5: test_xvasprintf_helper

static char *
test_xvasprintf_helper( const char *fmt, ... ) {
    va_list ap;
    va_start(ap, fmt );
    char *str = xvasprintf( fmt, ap );
    va_end( ap );
    return str;
}
开发者ID:karahiyo,项目名称:trema,代码行数:8,代码来源:wrapper_test.c

示例6: insert_header

/* Insert header, before specified header if not NULL, otherwise at end. */
int printflike3
insert_header(struct mail *m, const char *before, const char *fmt, ...)
{
	va_list		 ap;
	char		*hdr, *ptr;
	size_t		 hdrlen, len, off;
	u_int		 newlines;

	newlines = 1;
	if (before != NULL) {
		/* Insert before header. */
		ptr = find_header(m, before, &len, 0);
		if (ptr == NULL)
			return (-1);
		off = ptr - m->data;
	} else {
		/* Insert at the end. */
		if (m->body == 0) {
			/*
			 * Creating the headers section. Insert at the start,
			 * and add an extra newline.
			 */
			off = 0;
			newlines++;
		} else {
			/*
			 * Body points just after the blank line. Insert before
			 * the blank line.
			 */
			off = m->body - 1;
		}
	}

	/* Create the header. */
	va_start(ap, fmt);
	hdrlen = xvasprintf(&hdr, fmt, ap);
	va_end(ap);

	/* Include the newlines. */
	hdrlen += newlines;

	/* Make space for the header. */
	if (mail_resize(m, m->size + hdrlen) != 0) {
		xfree(hdr);
		return (-1);
	}
	ptr = m->data + off;
	memmove(ptr + hdrlen, ptr, m->size - off);

	/* Copy the header. */
	memcpy(ptr, hdr, hdrlen - newlines);
	memset(ptr + hdrlen - newlines, '\n', newlines);
	m->size += hdrlen;
	m->body += hdrlen;

	xfree(hdr);
	return (0);
}
开发者ID:avkrotov,项目名称:fdm,代码行数:59,代码来源:mail.c

示例7: flux_log_verror

void flux_log_verror (flux_t *h, const char *fmt, va_list ap)
{
    int saved_errno = errno;
    char *s = xvasprintf (fmt, ap);

    flux_log (h, LOG_ERR, "%s: %s", s, flux_strerror (errno));
    free (s);
    errno = saved_errno;
}
开发者ID:SteVwonder,项目名称:flux-core,代码行数:9,代码来源:flog.c

示例8: link_arg_f

static void link_arg_f(const char *fmt, ...)
{
   va_list ap;
   assert(n_args < MAX_ARGS);
   va_start(ap, fmt);
   args[n_args] = xvasprintf(fmt, ap);
   va_end(ap);
   args[++n_args] = NULL;
}
开发者ID:ifreemyli,项目名称:nvc,代码行数:9,代码来源:link.c

示例9: cfg_error

/* ARGSUSED */
void printflike2
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
{
	va_list	ap;

	va_start(ap, fmt);
	xvasprintf(&cfg_cause, fmt, ap);
	va_end(ap);
}
开发者ID:ThomasAdam,项目名称:tmux-ARCHIVED,代码行数:10,代码来源:cfg.c

示例10: ovsdb_error_valist

static struct ovsdb_error *
ovsdb_error_valist(const char *tag, const char *details, va_list args)
{
    struct ovsdb_error *error = xmalloc(sizeof *error);
    error->tag = tag ? tag : "ovsdb error";
    error->details = details ? xvasprintf(details, args) : NULL;
    error->syntax = NULL;
    error->errno_ = 0;
    return error;
}
开发者ID:JScheurich,项目名称:ovs,代码行数:10,代码来源:ovsdb-error.c

示例11: xasprintf

int
xasprintf (char **strp, const char *fmt, ...)
{
	va_list ap;
	int result;
	va_start (ap, fmt);
	result = xvasprintf (strp, fmt, ap);
	va_end (ap);
	return result;
}
开发者ID:FatLASP,项目名称:nagios-plugins,代码行数:10,代码来源:utils.c

示例12: tcl_error

static int tcl_error(Tcl_Interp *interp, const char *fmt, ...)
{
   va_list ap;
   va_start(ap, fmt);
   char *buf LOCAL = xvasprintf(fmt, ap);
   va_end(ap);

   Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
   return TCL_ERROR;
}
开发者ID:SnookEE,项目名称:nvc,代码行数:10,代码来源:shell.c

示例13: xasprintf

char *
xasprintf (const char *fmt, ...)
{
  char *buf;
  va_list ap;
  va_start (ap, fmt);
  buf = xvasprintf (fmt, ap);
  va_end (ap);
  return buf;
}
开发者ID:0day-ci,项目名称:gcc,代码行数:10,代码来源:xasprintf.c

示例14: xasprintf

// Die with an error message if we can't malloc() enough space and do an
// sprintf() into that space., sizeof() into that space.)
char* xasprintf(const char *format, ...)
{
    va_list p;
    char *string_ptr;

    va_start(p, format);
    string_ptr = xvasprintf(format, p);
    va_end(p);

    return string_ptr;
}
开发者ID:credmon,项目名称:libreport,代码行数:13,代码来源:xfuncs.c

示例15: action_error

action_error(struct action_context *ctx, const char *message, ...)
{
    if (action_error_handle_common(ctx)) {
        return;
    }

    va_list args;
    va_start(args, message);
    ctx->error = xvasprintf(message, args);
    va_end(args);
}
开发者ID:HaochuanXJTU,项目名称:ovs,代码行数:11,代码来源:actions.c


注:本文中的xvasprintf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。