dmenu: don't use getdelim() to read lines from stdin
Before adoption: this commit came in with the history the project adopted, so no landing records it.
We mark stdin as non-blocking. This causes getdelim() to fail if we receive input on stdin, but no delimiter. For example: printf("a line without a newline"); sleep(5); printf("\n"); printf("part of the"); sleep(5); printf(" next line\n"); Solution: roll our own getdelim() that reads directly from the stdin file descriptor, and buffers data locally. In short: * When poll() says there's data to read, try to fill up the local buffer. If the local buffer is already full, increase its size. * Consume as many lines as possible from the buffer. * Any remaining data (i.e. a trailing partial line) is memmoved() to the beginning of the buffer, and we then wait for poll() to signal input availability. * If stdin is closed, treat all remaining data as a line, and consume it.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+109 added−30 removed
- other:+109 added−30 removed