/* * nvasprintf() - implementation of asprintf() that checks return values; if an * error occurs, an error is printed to stderr and exit is called. * -- this function will only return on success. */ char *nvasprintf(const char *fmt, ...) { char *str; NV_VSNPRINTF(str, fmt); return str; } /* nvasprintf() */
void ctk_help_term(GtkTextBuffer *buffer, GtkTextIter *iter, const gchar *fmt, ...) { gchar *a, *b; NV_VSNPRINTF(a, fmt); b = g_strconcat("\n", a, NULL); gtk_text_buffer_insert_with_tags_by_name(buffer, iter, b, -1, CTK_HELP_BOLD_TAG, NULL); g_free(b); free(a); }
void ctk_help_para(GtkTextBuffer *buffer, GtkTextIter *iter, const gchar *fmt, ...) { gchar *a, *b; NV_VSNPRINTF(a, fmt); b = g_strconcat("\n", a, "\n", NULL); gtk_text_buffer_insert(buffer, iter, b, -1); g_free(b); free(a); }
/* * nv_append_sprintf() - similar to glib's g_string_append_printf(), except * instead of operating on a GString it operates on a (char **). Appends a * formatted string to the end of the dynamically-allocated string pointed to by * *buf (or the empty string if *buf is NULL), potentially reallocating the * string in the process. This function only returns on succcess. */ void nv_append_sprintf(char **buf, const char *fmt, ...) { char *prefix, *suffix; prefix = *buf; NV_VSNPRINTF(suffix, fmt); if (!prefix) { *buf = suffix; } else { *buf = nvstrcat(prefix, suffix, NULL); free(prefix); free(suffix); } }