mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Cleanup _get_message_from_editor a bit
* Fix `src/command/cmd_funcs.c:9463:9: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]` * Free memory earlier and on less places * Check for succesful open() and write()
This commit is contained in:
parent
7f5f334cd7
commit
9a9122c148
@ -9443,29 +9443,36 @@ _get_message_from_editor(gchar* message, gchar** returned_message)
|
||||
// create editor dir if not present
|
||||
char* jid = connection_get_barejid();
|
||||
gchar* path = files_get_account_data_path(DIR_EDITOR, jid);
|
||||
free(jid);
|
||||
if (g_mkdir_with_parents(path, S_IRWXU) != 0) {
|
||||
cons_show_error("Failed to create directory at '%s' with error '%s'", path, strerror(errno));
|
||||
free(jid);
|
||||
g_free(path);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// build temp file name. Example: /home/user/.local/share/profanity/editor/jid/compose.md
|
||||
char* filename = g_strdup_printf("%s/compose.md", path);
|
||||
free(jid);
|
||||
g_free(path);
|
||||
|
||||
GError* creation_error = NULL;
|
||||
GFile* file = g_file_new_for_path(filename);
|
||||
GFileOutputStream* fos = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, &creation_error);
|
||||
|
||||
free(filename);
|
||||
|
||||
if (message != NULL && strlen(message) > 0) {
|
||||
int fd_output_file = open(g_file_get_path(file), O_WRONLY);
|
||||
write(fd_output_file, message, strlen(message));
|
||||
if (fd_output_file < 0) {
|
||||
cons_show_error("Editor: Could not open file '%s': %s", file, strerror(errno));
|
||||
return TRUE;
|
||||
}
|
||||
if (-1 == write(fd_output_file, message, strlen(message))) {
|
||||
cons_show_error("Editor: failed to write '%s' to file: %s", message, strerror(errno));
|
||||
return TRUE;
|
||||
}
|
||||
close(fd_output_file);
|
||||
}
|
||||
|
||||
free(filename);
|
||||
|
||||
if (creation_error) {
|
||||
cons_show_error("Editor: could not create temp file");
|
||||
return TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user