void pdb_xml_abort (PdbXmlParser *parser, GQuark domain, gint code, const char *format, ...) { va_list ap; GError *error = NULL; GString *message = g_string_new (NULL); g_assert (parser->abort_error == NULL); g_string_append_printf (message, "%s:%i:%i: ", pdb_xml_get_current_filename (parser), pdb_xml_get_current_line_number (parser), pdb_xml_get_current_column_number (parser)); va_start (ap, format); g_string_append_vprintf (message, format, ap); va_end (ap); g_set_error_literal (&error, domain, code, message->str); g_string_free (message, TRUE); pdb_xml_abort_error (parser, error); }
static GSList * _list_append_val_strv (GSList *items, char **values, const char *format, ...) { if (!values) g_return_val_if_reached (items); /* Only add an item if the list of @values is not empty */ if (values[0]) { va_list args; guint i; GString *str = g_string_new (NULL); va_start (args, format); g_string_append_vprintf (str, format, args); va_end (args); g_string_append (str, values[0]); for (i = 1; values[i]; i++) { g_string_append_c (str, ' '); g_string_append (str, values[i]); } items = g_slist_prepend (items, g_string_free (str, FALSE)); } /* we take ownership of the values array and free it. */ g_strfreev (values); return items; }
void g_error_trace(GError ** e, const char *dom, int code, int line, const char *func, const char *file, const char *fmt, ...) { GString *gstr; va_list localVA; if (!e) return; gstr = g_string_new(""); if (line && func && file) g_string_printf(gstr, "(code=%i) [%s:%d] ", (code?code:(*e?(*e)->code:0)), func, line); va_start(localVA, fmt); g_string_append_vprintf(gstr, fmt, localVA); va_end(localVA); if (!*e) *e = g_error_new(g_quark_from_static_string(dom), code, gstr->str); else { g_string_append(gstr, "\n\t"); g_prefix_error(e, gstr->str); if (code) (*e)->code = code; } g_string_free(gstr, TRUE); }
void XI_g_string_printf(const char *filename, int linenumber, GString *string, const gchar *format, ...) { gchar *s; va_list args; va_start(args, format); for (s = strchr(format, '%'); s; s = strchr(++s, '%')) { gchar *next = va_arg(args, gchar *); if ((next == (gchar *)NULL) && (*(s + 1) == 's')) { gchar *msg = g_strdup_printf("%s\n%s\n\n%s:%d \"%s\"", _("BUG! Xiphos is about to crash due to a \"STRING\" error."), _("Please report this error to the Xiphos team with:"), filename, linenumber, format); gui_generic_warning_modal(msg); g_free(msg); abort(); } } va_end(args); /* real g_string_printf content */ g_string_truncate(string, 0); va_start(args, format); g_string_append_vprintf(string, format, args); va_end(args); }
static void assertion_fail (const char *msg, ...) { int i; GString* err = g_string_sized_new (100); CheckState *state = get_state (); g_string_append_printf (err, "Assertion failure in thread %p due to: ", mono_native_thread_id_get ()); va_list args; va_start (args, msg); g_string_append_vprintf (err, msg, args); va_end (args); g_string_append_printf (err, "\nLast %d state transitions: (most recent first)\n", state->transitions->len); for (i = state->transitions->len - 1; i >= 0; --i) { ThreadTransition *t = state->transitions->pdata [i]; char *bt = translate_backtrace (t->backtrace, t->size); g_string_append_printf (err, "[%s] %s -> %s (%d) %s%d at:\n%s", t->name, mono_thread_state_name (t->from_state), mono_thread_state_name (t->next_state), t->suspend_count, t->suspend_count_delta > 0 ? "+" : "", //I'd like to see this sort of values: -1, 0, +1 t->suspend_count_delta, bt); g_free (bt); } g_error (err->str); g_string_free (err, TRUE); }
void g_error_trace(GError ** e, const char *dom, int code, int line, const char *func, const char *file, const char *fmt, ...) { (void) line, (void) func, (void) file; if (!e) return; GString *gstr = g_string_new(""); #ifdef HAVE_EXTRA_DEBUG if (line && func && file) g_string_printf(gstr, "(code=%i) %s,%d ", (code?code:(*e?(*e)->code:0)), func, line); else #endif g_string_printf(gstr, "(code=%i) - ", (code?code:(*e?(*e)->code:0))); va_list localVA; va_start(localVA, fmt); g_string_append_vprintf(gstr, fmt, localVA); va_end(localVA); if (!*e) *e = g_error_new(g_quark_from_static_string(dom), code, "%s", gstr->str); else { g_string_append_c(gstr, ' '); g_prefix_error(e, "%s", gstr->str); if (code) (*e)->code = code; } g_string_free(gstr, TRUE); }
void ekg_debug_handler(int level, const char *format, va_list ap) { static GString *line = NULL; char *tmp = NULL; char *theme_format; int is_UI = 0; if (!config_debug) return; if (line) { g_string_append_vprintf(line, format, ap); if (line->len == 0 || line->str[line->len - 1] != '\n') return; line->str[line->len - 1] = '\0'; /* remove '\n' */ tmp = g_string_free(line, FALSE); line = NULL; } else { int tmplen = g_vasprintf(&tmp, format, ap); if (tmplen < 0 || !tmp) /* OutOfMemory? */ return; if (tmplen == 0 || tmp[tmplen - 1] != '\n') { line = g_string_new_len(tmp, tmplen); g_free(tmp); return; } tmp[tmplen - 1] = 0; /* remove '\n' */ } switch(level) { case 0: theme_format = "debug"; break; case DEBUG_IO: theme_format = "iodebug"; break; case DEBUG_IORECV: theme_format = "iorecvdebug"; break; case DEBUG_FUNCTION: theme_format = "fdebug"; break; case DEBUG_ERROR: theme_format = "edebug"; break; case DEBUG_WHITE: theme_format = "wdebug"; break; case DEBUG_WARN: theme_format = "warndebug"; break; case DEBUG_OK: theme_format = "okdebug"; break; default: theme_format = "debug"; break; } ekg_fix_utf8(tmp); /* debug message can contain random data */ buffer_add(&buffer_debug, theme_format, tmp); query_emit(NULL, "ui-is-initialized", &is_UI); if (is_UI && window_debug) { print_window_w(window_debug, EKG_WINACT_NONE, theme_format, tmp); } #ifdef STDERR_DEBUG /* STDERR debug */ else fprintf(stderr, "%s\n", tmp); #endif xfree(tmp); }
static void _log_args(GString *gs, const gchar *fmt, va_list vargs) { g_string_append_c(gs, ' '); g_string_append_c(gs, '['); if (fmt) g_string_append_vprintf(gs, fmt, vargs); g_string_append_c(gs, ']'); }
static void output(struct merge_options *o, const char *fmt, ...) { va_list ap; va_start(ap, fmt); g_string_append_vprintf(o->obuf, fmt, ap); g_string_append (o->obuf, "\n"); va_end(ap); }
void str_printf (GString * buffer, const char *format, ...) { va_list ap; va_start (ap, format); g_string_append_vprintf (buffer, format, ap); va_end (ap); }
static inline void append_report (GString **report, const gchar *format, ...) { va_list ap; if (!*report) *report = g_string_new (""); va_start (ap, format); g_string_append_vprintf (*report, format, ap); va_end (ap); }
void base_tool_output_color_append_string (ToolOutputColor color, gboolean color_term, GString *string, const char *fmt, ...) { va_list argv; g_string_append (string, base_tool_output_color_s (color, color_term)); va_start (argv, fmt); g_string_append_vprintf (string, fmt, argv); va_end (argv); g_string_append (string, base_tool_output_color_s (BASE_TOOL_COLOR_RESET, color_term)); }
void shovelerLogMessage(const char *file, int line, ShovelerLogLevel level, const char *message, ...) { if(shouldLog(level)) { va_list va; va_start(va, message); GString *assembled = g_string_new(""); g_string_append_vprintf(assembled, message, va); logCallbackFunction(file, line, level, assembled->str); g_string_free(assembled, true); } }
void mono_json_writer_printf(JsonWriter* writer, const gchar *format, ...) { g_assert (writer && "Expected a valid JSON writer instance"); va_list args; va_start (args, format); g_string_append_vprintf (writer->text, format, args); va_end (args); }
static G_GNUC_PRINTF(2, 3) void report(unsigned level, const char *fmt, ...) { va_list ap; if (report_str == NULL) return; va_start(ap, fmt); g_string_append_printf(report_str, "%*s", 2 * level, ""); g_string_append_vprintf(report_str, fmt, ap); g_string_append_printf(report_str, "\n"); va_end(ap); }
static void my_g_string_append_printf (GString * str, int depth, const gchar * format, ...) { va_list args; while (depth-- > 0) { g_string_append (str, " "); } va_start (args, format); g_string_append_vprintf (str, format, args); va_end (args); }
static inline void append_report (GString **report, const gchar *format, ...) { #if defined (_EGLIB_MAJOR) || GLIB_CHECK_VERSION(2,14,0) va_list ap; if (!*report) *report = g_string_new (""); va_start (ap, format); g_string_append_vprintf (*report, format, ap); va_end (ap); #else g_assert_not_reached (); #endif }
/** * g_vfs_ftp_task_sendv: * @task: the sending task * @flags: response flags to use when receiving the reply * @reply: %NULL or pointer to char array that takes the full reply from the * server * @format: format string to construct command from * (without trailing \r\n) * @varargs: arguments to format string * * This is the varargs version of g_vfs_ftp_task_send(). See that function * for details. * * Returns: the received FTP code or 0 on error. **/ guint g_vfs_ftp_task_sendv (GVfsFtpTask * task, GVfsFtpResponseFlags flags, char *** reply, const char * format, va_list varargs) { GString *command; gboolean retry_on_timeout = FALSE; guint response; if (g_vfs_ftp_task_is_in_error (task)) return 0; command = g_string_new (""); g_string_append_vprintf (command, format, varargs); g_string_append (command, "\r\n"); retry: if (task->conn == NULL) { if (!g_vfs_ftp_task_acquire_connection (task)) { g_string_free (command, TRUE); return 0; } retry_on_timeout = TRUE; } g_vfs_ftp_connection_send (task->conn, command->str, command->len, task->cancellable, &task->error); response = g_vfs_ftp_task_receive (task, flags, reply); /* NB: requires adaption if we allow passing 4xx responses */ if (retry_on_timeout && g_vfs_ftp_task_is_in_error (task) && !g_vfs_ftp_connection_is_usable (task->conn)) { g_vfs_ftp_task_clear_error (task); g_vfs_ftp_task_release_connection (task); goto retry; } g_string_free (command, TRUE); return response; }
static void error_handler(void *ctx, const char *format, ...) { GString *string = (GString *)ctx; va_list ap; va_start(ap, format); g_string_append_vprintf(string, format, ap); if (string->str[string->len - 1] == '\n') { string->str[string->len - 1] = '\0'; log4g_log_warn("%s", string->str); g_string_set_size(string, 0); } va_end(ap); }
static void add_fieldf(const char *format, ...) { SendOffset offset; va_list args; offset.offset = buffer->len; va_start (args, format); g_string_append_vprintf (buffer, format, args); va_end (args); offset.len = buffer->len - offset.offset; g_array_append_val (send_offsets, offset); }
void realm_handle_error (GError *error, const gchar *format, ...) { static gboolean diag_hint = TRUE; GString *message; gchar *remote; va_list va; if (realm_cancelled && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } #ifdef WITH_JOURNAL remote = error ? g_dbus_error_get_remote_error (error) : NULL; if (diag_hint && realm_operation_id && !realm_verbose && g_strcmp0 (remote, REALM_DBUS_ERROR_NOT_AUTHORIZED) != 0) { g_printerr ("See: journalctl REALMD_OPERATION=%s\n", realm_operation_id); diag_hint = FALSE; } g_free (remote); #endif message = g_string_new (""); g_string_append_printf (message, "%s: ", g_get_prgname ()); if (format) { va_start (va, format); g_string_append_vprintf (message, format, va); va_end (va); } if (error) { g_dbus_error_strip_remote_error (error); if (format) g_string_append (message, ": "); g_string_append (message, error->message); g_error_free (error); } g_printerr ("%s\n", message->str); g_string_free (message, TRUE); }
void str_printf (GString * buffer, const char *format, ...) { va_list ap; va_start (ap, format); #if GLIB_CHECK_VERSION (2, 14, 0) g_string_append_vprintf (buffer, format, ap); #else { gchar *tmp; tmp = g_strdup_vprintf (format, ap); g_string_append (buffer, tmp); g_free (tmp); } #endif va_end (ap); }
void mono_error_set_field_missing (MonoError *error, MonoClass *klass, const char *field_name, MonoType *sig, const char *reason, ...) { char *result; GString *res; res = g_string_new ("Field not found: "); if (sig) { mono_type_get_desc (res, sig, TRUE); g_string_append_c (res, ' '); } if (klass) { if (m_class_get_name_space (klass)) { g_string_append (res, m_class_get_name_space (klass)); g_string_append_c (res, '.'); } g_string_append (res, m_class_get_name (klass)); } else { g_string_append (res, "<unknown type>"); } g_string_append_c (res, '.'); if (field_name) g_string_append (res, field_name); else g_string_append (res, "<unknown field>"); if (reason && *reason) { va_list args; va_start (args, reason); g_string_append (res, " Due to: "); g_string_append_vprintf (res, reason, args); va_end (args); } result = res->str; g_string_free (res, FALSE); mono_error_set_specific (error, MONO_ERROR_MISSING_FIELD, result); }
static void print_message (const glibtop *server, int message_level, const char *format, int error, va_list args) { const char *level; GString* message; message = g_string_new(NULL); g_string_printf(message, "%s", (server && server->name ? server->name : DEFAULT_NAME)); if (server->pid) { g_string_append_printf(message, "(c=%u/s=%u)", getpid(), server->pid); } else { g_string_append_printf(message, "(c=%u)", getpid()); } switch (message_level) { case MESSAGE_DEBUG: level = "DEBUG"; break; case MESSAGE_WARNING: level = "WARNING"; break; case MESSAGE_ERROR: level = "ERROR"; break; default: level = "UNKNOWN"; } g_string_append_printf(message, ": [%s] ", level); g_string_append_vprintf(message, format, args); if (error) { g_string_append_printf(message, ": %s", g_strerror(error)); } g_string_append_c(message, '\n'); fputs(message->str, stderr); g_string_free(message, TRUE); }
void realm_print_error (const gchar *format, ...) { GString *message; va_list va; va_start (va, format); message = g_string_new (""); g_string_append_printf (message, "%s: ", g_get_prgname ()); va_start (va, format); g_string_append_vprintf (message, format, va); va_end (va); g_printerr ("%s\n", message->str); g_string_free (message, TRUE); }
void li_log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) { va_list ap; GString *log_line = srv->log.log_line; if (!srv->log.levels[log_level]) return; g_string_truncate(log_line, 0); /* for normal error messages, we prepend a timestamp */ if (flags & LI_LOG_FLAG_TIMESTAMP) { GString *log_ts = srv->log.ts_cache; time_t cur_ts; cur_ts = (time_t)ev_now(srv->loop); if (cur_ts != srv->log.last_ts) { gsize s; struct tm tm; g_string_set_size(log_ts, 255); #ifdef HAVE_LOCALTIME_R s = strftime(log_ts->str, log_ts->allocated_len, "%Y-%m-%d %H:%M:%S %Z: ", localtime_r(&cur_ts, &tm)); #else s = strftime(log_ts->str, log_ts->allocated_len, "%Y-%m-%d %H:%M:%S %Z: ", localtime(&cur_ts)); #endif g_string_set_size(log_ts, s); srv->log.last_ts = cur_ts; } g_string_append_len(log_line, GSTR_LEN(log_ts)); } va_start(ap, fmt); g_string_append_vprintf(log_line, fmt, ap); va_end(ap); g_string_append_len(log_line, CONST_STR_LEN("\n")); fprintf(stderr, "%s", log_line->str); }
void error_append_hint(Error **errp, const char *fmt, ...) { va_list ap; int saved_errno = errno; Error *err; if (!errp) { return; } err = *errp; assert(err && errp != &error_abort && errp != &error_fatal); if (!err->hint) { err->hint = g_string_new(NULL); } va_start(ap, fmt); g_string_append_vprintf(err->hint, fmt, ap); va_end(ap); errno = saved_errno; }
static void httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...) { g_autoptr(GString) str = NULL; va_list args; gsize written; if (!httpd->log) return; { g_autoptr(GDateTime) now = g_date_time_new_now_local (); g_autofree char *timestamp = g_date_time_format (now, "%F %T"); str = g_string_new (timestamp); g_string_append_printf (str, ".%06d - ", g_date_time_get_microsecond (now)); } va_start (args, format); g_string_append_vprintf (str, format, args); va_end (args); (void)g_output_stream_write_all (httpd->log, str->str, str->len, &written, NULL, NULL); }
/** @private */ SRD_PRIV void srd_exception_catch(const char *format, ...) { PyObject *etype, *evalue, *etb, *py_str; PyTracebackObject *py_tb; GString *msg; va_list args; char *ename, *str, *tracestr; if (!PyErr_Occurred()) /* Nothing is wrong. */ return; PyErr_Fetch(&etype, &evalue, &etb); PyErr_NormalizeException(&etype, &evalue, &etb); if (!(py_str = PyObject_Str(evalue))) { /* Shouldn't happen. */ srd_dbg("Failed to convert exception value to string."); return; } /* Send the exception error message(s) to srd_err(). */ if (evalue) ename = (char *)Py_TYPE(evalue)->tp_name; else /* Can be NULL. */ ename = "(unknown exception)"; msg = g_string_sized_new(128); g_string_append(msg, ename); g_string_append(msg, ": "); va_start(args, format); g_string_append_vprintf(msg, format, args); va_end(args); py_str_as_str(py_str, &str); g_string_append(msg, str); Py_DecRef(py_str); srd_err(msg->str); /* Send a more precise error location to srd_dbg(), if we have it. */ if (etb && etb != Py_None) { tracestr = NULL; py_tb = (PyTracebackObject *)etb; py_str = PyUnicode_FromFormat("%U:%d in %U", py_tb->tb_frame->f_code->co_filename, py_tb->tb_frame->f_lineno, py_tb->tb_frame->f_code->co_name); py_str_as_str(py_str, &tracestr); Py_DecRef(py_str); g_string_printf(msg, "%s in %s: %s", ename, tracestr, str); srd_dbg(msg->str); g_free(tracestr); } g_free(str); g_string_free(msg, TRUE); Py_XDECREF(etype); Py_XDECREF(evalue); Py_XDECREF(etb); /* Just in case. */ PyErr_Clear(); }
/* * Sets @error to a method missing error. */ void mono_error_set_method_missing (MonoError *error, MonoClass *klass, const char *method_name, MonoMethodSignature *sig, const char *reason, ...) { int i; char *result; GString *res; res = g_string_new ("Method not found: "); if (sig) { mono_type_get_desc (res, sig->ret, TRUE); g_string_append_c (res, ' '); } if (klass) { if (m_class_get_name_space (klass)) { g_string_append (res, m_class_get_name_space (klass)); g_string_append_c (res, '.'); } g_string_append (res, m_class_get_name (klass)); } else { g_string_append (res, "<unknown type>"); } g_string_append_c (res, '.'); if (method_name) g_string_append (res, method_name); else g_string_append (res, "<unknown method>"); if (sig) { if (sig->generic_param_count) { g_string_append_c (res, '<'); for (i = 0; i < sig->generic_param_count; ++i) { if (i > 0) g_string_append (res, ","); g_string_append_printf (res, "!%d", i); } g_string_append_c (res, '>'); } g_string_append_c (res, '('); for (i = 0; i < sig->param_count; ++i) { if (i > 0) g_string_append_c (res, ','); mono_type_get_desc (res, sig->params [i], TRUE); } g_string_append_c (res, ')'); } if (reason && *reason) { va_list args; va_start (args, reason); g_string_append (res, " Due to: "); g_string_append_vprintf (res, reason, args); va_end (args); } result = res->str; g_string_free (res, FALSE); mono_error_set_specific (error, MONO_ERROR_MISSING_METHOD, result); }