about summary refs log tree commit diff stats
path: root/src/command/cmd_funcs.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-04-16 18:06:30 +0200
committerMichael Vetter <jubalh@iodoru.org>2021-04-16 18:06:30 +0200
commit8be46422d2ca5afff675ef3f7a2117c097a642a7 (patch)
tree51447b5ad73535436f433d87afb44a8714ab54f2 /src/command/cmd_funcs.c
parent880ce20018d8b4b583da7917a3cc5aa41c656531 (diff)
downloadprofani-tty-8be46422d2ca5afff675ef3f7a2117c097a642a7.tar.gz
editor: Use g_strdup_printf() instead of g_string_new()
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r--src/command/cmd_funcs.c15
1 files changed, 4 insertions, 11 deletions
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;
     }