Hello,
When using gmni -i
, I find that the status line is printed after the body if the output is not a TTY.
Example:
$ gmni -i gemini://celehner.com/hi.txt
20 text/plain
Hello, world!
$ gmni -i gemini://celehner.com/hi.txt | cat
Hello, world!
20 text/plain
Cannot reproduce:
$ git log --oneline | head -n1 174fbd5 Fix memory leaks $ git status -s # No output means no local changes $ make clean all >/dev/null $ ./gmni -i gemini://celehner.com/hi.txt | cat 20 text/plain Hello, world!
Still happens for me on
174fbd5
. Using Debian Testing, x64_64, glibc, bash.It is because of mixing
write
with buffered I/O (printf
). The text output with printf ends up buffered until after the body is already written. Any of the following should fix it:
- Disable output buffering:
setvbuf(stdout, NULL, _IONBF, 0)
- Call
fflush(stdout)
after eachprintf
beforewrite
- Use unbuffered formatted output functions to print status line:
dprintf
instead ofprintf
- Use buffered I/O to write body:
fwrite
instead ofwrite
Ticket resolved: fixed
Thanks, ~sircmpwn
Thank ~ecs, he wrote the patch
Thanks, ~ecs!