1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

editor: Use g_strdup_printf() instead of g_string_new()

This commit is contained in:
Michael Vetter 2021-04-16 18:06:30 +02:00
parent 880ce20018
commit 8be46422d2

View File

@ -9314,29 +9314,22 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args)
gboolean gboolean
cmd_editor(ProfWin* window, const char* const command, gchar** args) 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(); xmpp_ctx_t* const ctx = connection_get_ctx();
if (!ctx) { if (!ctx) {
cons_show("Editor: Not connection"); log_debug("Editor: No connection");
return TRUE; return TRUE;
} }
// build temp file name. Example: /tmp/profanity-f2f271dd-98c8-4118-8d47-3bd49c8e2e63.txt
char* uuid = xmpp_uuid_gen(ctx); 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) { if (uuid) {
xmpp_free(ctx, 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 // Check if file exists and create file
if (g_file_test(filename, G_FILE_TEST_EXISTS)) { if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
cons_show("Editor: The temp file exists"); cons_show("Editor: The temp file exists");
g_string_free(tempfile, TRUE);
return TRUE; return TRUE;
} }