static const char * make_message (state_t *state, const char *format, ...) { va_list args; char *message; char *result; va_start (args, format); g_vasprintf (&message, format, args); va_end (args); result = g_hash_table_lookup (state->unique_comms, message); if (result) { g_free (message); } else { result = message; g_hash_table_insert (state->unique_comms, result, result); } return result; }
ATTR_PRINTF_FORMAT (2,3) gchar * _lp_event_to_string (lp_Event *event, const gchar *fmt, ...) { va_list args; gchar *suffix = NULL; gchar *str; gint n; va_start (args, fmt); n = g_vasprintf (&suffix, fmt, args); g_assert_nonnull (suffix); g_assert (n >= 0); va_end (args); str = g_strdup_printf ("\ %s at %p\n\ source: %s at %p\n\ mask: 0x%x\n\ %s\ ", G_OBJECT_TYPE_NAME (event), G_TYPE_CHECK_INSTANCE_CAST (event, G_OBJECT_TYPE (event), gpointer), LP_IS_SCENE (event->priv->source) ? "lp_Scene" : LP_IS_MEDIA (event->priv->source) ? "lp_Media" : "unknown", event->priv->source, (guint) event->priv->mask, suffix); g_assert_nonnull (str); g_free (suffix); return str; }
void lr_downloadtarget_set_error(LrDownloadTarget *target, LrRc code, const char *format, ...) { assert(target); assert(code == LRE_OK || format); if (format) { int ret; va_list vl; gchar *message = NULL; va_start(vl, format); ret = g_vasprintf(&message, format, vl); va_end(vl); if (ret < 0) { assert(0); target->err = ""; return; } target->err = lr_string_chunk_insert(target->chunk, message); g_free(message); } else { target->err = NULL; } target->rcode = code; }
RESULT FAILED(const gchar *format, ...) { gchar *ret; va_list args; gint n; #if !defined(HAVE_VASPRINTF) && !defined(_EGLIB_MAJOR) /* We are linked against the real glib, no vasprintf */ g_assert_not_reached (); return NULL; #else va_start(args, format); n = g_vasprintf(&ret, format, args); va_end(args); if(n == -1) { last_result = NULL; return NULL; } last_result = ret; return ret; #endif }
static void log_with_msgid (const gchar *msgid, GLogLevelFlags log_level, const gchar *numeric_log_level, const gchar *format, va_list args) { G_STATIC_ASSERT (G_LOG_DOMAIN != NULL); G_STATIC_ASSERT (G_LOG_DOMAIN[0] != '\0'); g_autofree gchar *message = NULL; /* Apparently the version of GCC in Endless ignores the * G_GNUC_PRINTF annotation that has a zero as the second parameter, * so it suggests to use this attribute. Similarly, so does Clang 4. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" #pragma GCC diagnostic ignored "-Wformat-nonliteral" gint message_length = g_vasprintf (&message, format, args); #pragma GCC diagnostic pop const GLogField fields[] = { { "MESSAGE", message, message_length }, { "MESSAGE_ID", msgid, EOS_UPDATER_MSGID_LENGTH }, { "PRIORITY", numeric_log_level, -1 }, /* strlen (G_LOG_DOMAIN) should be folded to a constant at a * compilation time, because G_LOG_DOMAIN is a macro defining a * literal string */ { "GLIB_DOMAIN", G_LOG_DOMAIN, strlen (G_LOG_DOMAIN) }, }; g_log_structured_array (log_level, fields, G_N_ELEMENTS (fields)); }
void parole_debug_enum_full (const gchar *func, const gchar *file, gint line, gint v_enum, GType type, const gchar *format, ...) { va_list args; gchar *buffer; gchar *content = NULL; GValue __value__ = { 0, }; g_value_init (&__value__, type); g_value_set_enum (&__value__, v_enum); content = g_strdup_value_contents (&__value__); va_start (args, format); g_vasprintf (&buffer, format, args); va_end (args); fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func); fprintf(stdout, "%s: %s", buffer, content); fprintf(stdout, "\n"); g_value_unset (&__value__); g_free (content); g_free (buffer); }
void warlock_send (const char *fmt, ...) { va_list list; char *string; char *to_send; g_assert (fmt != NULL); va_start (list, fmt); g_vasprintf (&string, fmt, list); va_end (list); to_send = g_strconcat (string, "\n", NULL); g_free (string); if (preferences_get_bool (preferences_get_key (PREF_ECHO))) { echo (to_send); } if (connection != NULL) { simu_connection_send (connection, to_send); } g_free (to_send); }
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); }
print_expr (const char* frm, ...) { char *expr, *expr_orig; va_list ap; ssize_t rv; size_t exprlen, lenlen; char cookie[16]; static int outfd = 0; #if defined(__CYGWIN__ )&& !defined (_WIN32) const size_t writestep = 4096 * 16; size_t bytestowrite = 0; #endif if (outfd == 0) outfd = fileno (stdout); expr = NULL; va_start (ap, frm); exprlen = g_vasprintf (&expr, frm, ap); va_end (ap); /* this cookie tells the frontend where to expect the next * expression */ cookie[0] = COOKIE_PRE; lenlen = sprintf(cookie + 1, "%x", (unsigned)exprlen + 1); /* + 1 for \n */ cookie[lenlen + 1] = COOKIE_POST; /* write the cookie, ie. * COOKIE_PRE <len-of-following-sexp-in-hex> COOKIE_POST */ rv = write (outfd, cookie, lenlen + 2); if (rv != -1) { expr_orig = expr; #if defined (__CYGWIN__) && !defined(_WIN32) /* CYGWIN doesn't like big packets */ while (exprlen > 0) { bytestowrite = exprlen > writestep ? writestep : exprlen; rv = write(outfd, expr, bytestowrite); expr += bytestowrite; exprlen -= bytestowrite; } #else rv = write (outfd, expr, exprlen); #endif g_free (expr_orig); } if (rv != -1) rv = write (outfd, "\n", 1); if (rv == -1) { g_critical ("%s: write() failed: %s", __func__, strerror(errno)); /* terminate ourselves */ raise (SIGTERM); } }
/** * Writes a formatted string to a VFS stream via a va_list of args. * * @param stream A #VFSFile object representing the stream. * @param format A printf-style format string. * @param args A va_list of args to use. * @return value The amount of bytes written. */ EXPORT int vfs_vfprintf(VFSFile *stream, char const *format, va_list args) { char *string; int rv = g_vasprintf(&string, format, args); if (rv < 0) return rv; rv = vfs_fputs(string, stream); g_free(string); return rv; }
v9fs_string_sprintf(V9fsString *str, const char *fmt, ...) { va_list ap; v9fs_string_free(str); va_start(ap, fmt); str->size = g_vasprintf(&str->data, fmt, ap); va_end(ap); }
void exec_cmd_add_arg (ExecCmd *e, const gchar *format, ...) { g_return_if_fail(format != NULL); va_list va; va_start(va, format); gchar *arg = NULL; g_vasprintf(&arg, format, va); va_end(va); g_ptr_array_add(e->args, arg); }
static void error_handler(const char *module, const char *format, va_list arguments) { gchar *message; g_vasprintf(&message, format, arguments); g_warning("%s", message); g_free(message); }
static void g_string_append_printf_internal (GString *string, const gchar *fmt, va_list args) { gchar *buffer; gint length; length = g_vasprintf (&buffer, fmt, args); g_string_append_len (string, buffer, length); g_free (buffer); }
gint VMToolsAsprintf(gchar **string, gchar const *format, ...) { gint cnt; va_list args; va_start(args, format); cnt = g_vasprintf(string, format, args); va_end(args); return cnt; }
gchar * g_strdup_vprintf (const gchar *format, va_list args) { int n; char *ret; n = g_vasprintf (&ret, format, args); if (n == -1) return NULL; return ret; }
static GError * g_error_vnew (gpointer domain, gint code, const char *format, va_list ap) { GError *err = g_new (GError, 1); err->domain = domain; err->code = code; if (g_vasprintf (&err->message, format, ap) == -1) err->message = g_strdup_printf ("internal: invalid format string %s", format); return err; }
void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args) { char *msg; if (!default_log_func) default_log_func = g_log_default_handler; if (g_vasprintf (&msg, format, args) < 0) return; default_log_func (log_domain, log_level, msg, default_log_func_user_data); g_free (msg); }
void echo_f (const char *fmt, ...) { va_list list; char *str; va_start (list, fmt); g_vasprintf (&str, fmt, list); va_end (list); echo (str); g_free (str); }
gchar * g_strdup_printf (const gchar *format, ...) { gchar *ret; va_list args; int n; va_start (args, format); n = g_vasprintf (&ret, format, args); va_end (args); if (n == -1) return NULL; return ret; }
GError * g_error_new (gpointer domain, gint code, const char *format, ...) { va_list args; GError *err = g_new (GError, 1); err->domain = domain; err->code = code; va_start (args, format); if (g_vasprintf (&err->message, format, args) == -1) err->message = g_strdup_printf ("internal: invalid format string %s", format); va_end (args); return err; }
void ToolsCmd_PrintErr(const char *fmt, ...) { if (!gQuiet) { gchar *str; va_list args; va_start(args, fmt); g_vasprintf(&str, fmt, args); va_end(args); g_printerr("%s", str); g_free(str); } }
/* ACPI 1.0b: 16.2.3 Data Objects Encoding: String */ Aml *aml_string(const char *name_format, ...) { Aml *var = aml_opcode(0x0D /* StringPrefix */); va_list ap; char *s; int len; va_start(ap, name_format); len = g_vasprintf(&s, name_format, ap); va_end(ap); g_array_append_vals(var->buf, s, len + 1); g_free(s); return var; }
static gboolean pgm_query_vexec( PgmQuery *query, const gchar *format, va_list va ) { gchar *query_str; g_return_val_if_fail( query != NULL, FALSE ); g_return_val_if_fail( query->database != NULL, FALSE ); if( !pgm_database_connect( query->database ) ) return FALSE; g_vasprintf( &query_str, format, va ); if( query->is_copy ) { query->is_copy = FALSE; query->result = NULL; } if( query->result ) { PQclear( query->result ); query->result = NULL; } if( format == NULL || *format == 0 ) return TRUE; pgm_main_window_start_wait(); query->result = PQexec( query->database->connection, query_str ); pgm_main_window_stop_wait(); g_signal_emit( query, pgm_query_signals[ SIGNAL_EXECUTED ], 0 ); if( PQresultStatus( query->result ) != PGRES_COMMAND_OK && PQresultStatus( query->result ) != PGRES_TUPLES_OK ) { PQclear( query->result ); query->result = NULL; pgm_main_window_show_message_dialog( GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error executing query:\n%s", PQerrorMessage( query->database->connection ) ); return FALSE; } if( query->last_query ) g_free( query->last_query ); query->last_query = g_strdup( query_str ); return TRUE; }
/** * egg_debug_real: **/ void egg_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...) { va_list args; gchar *buffer = NULL; if (!egg_debug_is_verbose () && !egg_debug_filter_module (file) && !egg_debug_filter_function (func)) return; va_start (args, format); g_vasprintf (&buffer, format, args); va_end (args); egg_debug_print_line (func, file, line, buffer, CONSOLE_BLUE); g_free (buffer); }
/** * egg_debug_real: **/ void egg_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...) { va_list args; gchar *buffer = NULL; if (!egg_debug_enabled ()) return; va_start (args, format); g_vasprintf (&buffer, format, args); va_end (args); pk_print_line (func, file, line, buffer, CONSOLE_BLUE); g_free(buffer); }
/** * egg_controller_resolve_printf: * @format: A printf format for building a path * * Resolves a controller by first building a path and then calling * egg_controller_resolve(). * * Return value: An #EggController or %NULL */ EggController* egg_controller_resolve_printf (const gchar *format, ...) { EggController *controller = NULL; gchar *path = NULL; va_list args; va_start (args, format); g_vasprintf (&path, format, args); va_end (args); if (path) { controller = egg_controller_resolve (path); g_free (path); } return controller; }
void g_printerr (const gchar *format, ...) { char *msg; va_list args; va_start (args, format); if (g_vasprintf (&msg, format, args) < 0) { va_end (args); return; } va_end (args); if (!stderr_handler) stderr_handler = default_stderr_handler; stderr_handler (msg); g_free (msg); }
print_expr (const char* frm, ...) { char *expr; va_list ap; ssize_t rv; size_t exprlen, lenlen; char cookie[16]; static int outfd = 0; if (outfd == 0) outfd = fileno (stdout); expr = NULL; va_start (ap, frm); exprlen = g_vasprintf (&expr, frm, ap); va_end (ap); /* this cookie tells the frontend where to expect the next * expression */ cookie[0] = COOKIE_PRE; lenlen = sprintf(cookie + 1, "%x", (unsigned)exprlen + 1); /* + 1 for \n */ cookie[lenlen + 1] = COOKIE_POST; /* write the cookie, ie. * COOKIE_PRE <len-of-following-sexp-in-hex> COOKIE_POST */ rv = write (outfd, cookie, lenlen + 2); if (rv != -1) { rv = write (outfd, expr, exprlen); g_free (expr); } if (rv != -1) rv = write (outfd, "\n", 1); if (rv == -1) { g_critical ("%s: write() failed: %s", __FUNCTION__, strerror(errno)); /* terminate ourselves */ raise (SIGTERM); } }
/** * egg_warning_real: **/ void egg_warning_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...) { va_list args; gchar *buffer = NULL; if (!egg_debug_is_verbose () && !egg_debug_filter_module (file) && !egg_debug_filter_function (func)) return; va_start (args, format); g_vasprintf (&buffer, format, args); va_end (args); /* do extra stuff for a warning */ if (!egg_debug_is_console ()) printf ("*** WARNING ***\n"); egg_debug_print_line (func, file, line, buffer, CONSOLE_RED); g_free (buffer); }