snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit acfe4b4fb539a138428dfba1047cde8da747916f
parent 6b4b3317e3ba5fb6570c43a307383b43cd609eb1
Author: grunfink <grunfink@noreply.codeberg.org>
Date:   Wed,  5 Feb 2025 09:18:29 +0000

Merge pull request 'Allow multiple editors at the same time' (#297) from inz/snac2:temp-file into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/297

Diffstat:
Mmain.c | 35+++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/main.c b/main.c @@ -676,19 +676,25 @@ int main(int argc, char *argv[]) if (strcmp(url, "-e") == 0) { /* get the content from an editor */ +#define EDITOR "$EDITOR " + char cmd[] = EDITOR "/tmp/snac-XXXXXX"; FILE *f; - - unlink("/tmp/snac-edit.txt"); - system("$EDITOR /tmp/snac-edit.txt"); - - if ((f = fopen("/tmp/snac-edit.txt", "r")) != NULL) { - content = xs_readall(f); - fclose(f); - - unlink("/tmp/snac-edit.txt"); - } - else { - printf("Nothing to send\n"); + int fd = mkstemp(cmd + strlen(EDITOR)); + + if (fd >= 0) { + int status = system(cmd); + + if (WIFEXITED(status) && WEXITSTATUS(status) == 0 && (f = fdopen(fd, "r")) != NULL) { + content = xs_readall(f); + fclose(f); + unlink(cmd + strlen(EDITOR)); + } else { + printf("Nothing to send\n"); + close(fd); + return 1; + } + } else { + fprintf(stderr, "Temp file creation failed\n"); return 1; } } @@ -700,6 +706,11 @@ int main(int argc, char *argv[]) else content = xs_dup(url); + if (!content || !*content) { + printf("Nothing to send\n"); + return 1; + } + int scope = 0; if (strcmp(cmd, "note_mention") == 0) scope = 1;