void log_printf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, ...) { char *string; va_list ap; count++; if (level > debug_level) return; va_start(ap, format); string = alloc_vprintf(format, ap); if (string != NULL) { strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one *char longer */ log_puts(level, file, line, function, string); free(string); } va_end(ap); }
char *alloc_printf(const char *fmt, ...) { va_list ap; char *msg; va_start(ap, fmt); msg = alloc_vprintf(fmt, ap); va_end(ap); return msg; }
char *alloc_printf(const char *format, ...) { char *string; va_list ap; va_start(ap, format); string = alloc_vprintf(format, ap); va_end(ap); return string; }
int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap) { char mem[MG_BUF_LEN], *buf = mem; int len; if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) { len = mg_write(conn, buf, (size_t) len); } if (buf != mem && buf != NULL) { free(buf); } return len; }
int command_run_linef(struct command_context *context, const char *format, ...) { int retval = ERROR_FAIL; char *string; va_list ap; va_start(ap, format); string = alloc_vprintf(format, ap); if (string != NULL) { retval = command_run_line(context, string); free(string); } va_end(ap); return retval; }
static int mg_chunked_printf(struct mg_connection *conn, const char *fmt, ...) { char mem[MG_BUF_LEN], *buf = mem; int len; va_list ap; va_start(ap, fmt); if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) { len = mg_printf(conn, "%X\r\n%s\r\n", len, buf); } if (buf != mem && buf != NULL) { free(buf); } return len; }
END_TEST static int alloc_printf(char **buf, size_t size, const char *fmt, ...) { /* Test helper function - adapted from unit_test.c */ /* Copyright (c) 2013-2015 the Civetweb developers */ /* Copyright (c) 2004-2013 Sergey Lyubka */ va_list ap; int ret = 0; va_start(ap, fmt); ret = alloc_vprintf(buf, *buf, size, fmt, ap); va_end(ap); return ret; }
static int openocd_jim_vfprintf(void *cookie, const char *fmt, va_list ap) { char *cp; int n; Jim_Interp *interp; n = -1; interp = cookie; if (interp == NULL) return n; cp = alloc_vprintf(fmt, ap); if (cp) { LOG_USER_N("%s", cp); n = strlen(cp); free(cp); } return n; }
void command_print_sameline(struct command_context *context, const char *format, ...) { char *string; va_list ap; va_start(ap, format); string = alloc_vprintf(format, ap); if (string != NULL) { /* we want this collected in the log + we also want to pick it up as a tcl return * value. * * The latter bit isn't precisely neat, but will do for now. */ LOG_USER_N("%s", string); /* We already printed it above * command_output_text(context, string); */ free(string); } va_end(ap); }
char *create_fmt_errno_message(const char *file, int line, int e, const char *fmt, va_list ap) { char *msg1, *msg2; va_list tmp_ap; va_copy(tmp_ap, ap); msg1 = alloc_vprintf(fmt, tmp_ap); va_end(tmp_ap); if (msg1) { if (e) msg2 = alloc_printf("fatal error (file %s, line %d) in \"%s\": error %d (%s)", file, line, msg1, e, strerror(e)); else msg2 = alloc_printf("fatal error (file %s, line %d): \"%s\"", file, line, msg1); } else { if (e) msg2 = alloc_printf("fatal error (file %s, line %d): error %d (%s)", file, line, e, strerror(e)); else msg2 = alloc_printf("fatal error (file %s, line %d)", file, line); } free(msg1); return msg2; }
void log_vprintf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, va_list args) { char *tmp; count++; if (level > debug_level) return; tmp = alloc_vprintf(format, args); if (!tmp) return; /* * Note: alloc_vprintf() guarantees that the buffer is at least one * character longer. */ strcat(tmp, "\n"); log_puts(level, file, line, function, tmp); free(tmp); }
void log_printf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, ...) { char *string; va_list ap; count++; if (level > debug_level) return; va_start(ap, format); string = alloc_vprintf(format, ap); if (string != NULL) { log_puts(level, file, line, function, string); free(string); } va_end(ap); }
void log_impl(int prefix, int suffix, const char *fun, const char *fmt, va_list ap) { char *msg1, *msg2; struct timeval now; struct tm *tm; gettimeofday(&now, 0); tm = localtime(&now.tv_sec); msg1 = alloc_vprintf(fmt, ap); if (prefix) msg2 = alloc_printf("%04d-%02d-%02d %02d:%02d:%02d.%06ld %d %s: %s%s" , tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday , tm->tm_hour, tm->tm_min, tm->tm_sec, (long) now.tv_usec , getpid(), fun, msg1, (suffix ? "\n" : "")); else msg2 = alloc_printf("%s%s", msg1, (suffix ? "\n" : "")); /* Uncommenting the printf below will cause output to be displayed on the console until erld detaches. */ /* printf("%s", msg2); */ log_write(msg2, strlen(msg2)); free(msg2); free(msg1); }
static int alloc_printf(char **buf, size_t size, char *fmt, ...) { va_list ap; va_start(ap, fmt); return alloc_vprintf(buf, size, fmt, ap); }