From 8be46422d2ca5afff675ef3f7a2117c097a642a7 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 16 Apr 2021 18:06:30 +0200 Subject: editor: Use g_strdup_printf() instead of g_string_new() --- src/command/cmd_funcs.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/command/cmd_funcs.c') diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index a37c9b16..9c9674cc 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9314,29 +9314,22 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args) gboolean cmd_editor(ProfWin* window, const char* const command, gchar** args) { - /* Build temp file name */ - GString* tempfile = g_string_new(g_get_tmp_dir()); - g_string_append(tempfile, "/profanity-"); xmpp_ctx_t* const ctx = connection_get_ctx(); if (!ctx) { - cons_show("Editor: Not connection"); + log_debug("Editor: No connection"); return TRUE; } + + // build temp file name. Example: /tmp/profanity-f2f271dd-98c8-4118-8d47-3bd49c8e2e63.txt char* uuid = xmpp_uuid_gen(ctx); - g_string_append(tempfile, uuid); + char* filename = g_strdup_printf("%s%s%s.txt", g_get_tmp_dir(), "/profanity-", uuid); if (uuid) { xmpp_free(ctx, uuid); } - g_string_append(tempfile, ".txt"); - - // tempfile should be something like - // /tmp/profanity-f2f271dd-98c8-4118-8d47-3bd49c8e2e63.txt - const char* filename = tempfile->str; // Check if file exists and create file if (g_file_test(filename, G_FILE_TEST_EXISTS)) { cons_show("Editor: The temp file exists"); - g_string_free(tempfile, TRUE); return TRUE; } -- cgit 1.4.1-2-gfad0