本文整理汇总了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;
}
}
}
示例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);
}
示例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);
}
示例4: xvasprintf_wrapper
xvasprintf_wrapper(char **strp, const char *format, ...)
{
va_list args;
va_start(args, format);
xvasprintf(strp, format, args);
va_end(args);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}