Hi PƔdraig,
Thanks for answering. So, we have the multibyte problem and the
newline-included problem.
PƔdraig Brady wrote:
The code seems to follow the man page and includes the \n in the char count.
Note fold -w does not count the newline which is what I'd expect.
I ran this test case with various 'fmt' implementations:
$ echo 'Hello world' | fmt -w 11
Hello
world
$ echo 'Hello world' | fmt -w 12
Hello world
The minimum -w option that produces a single line:
GNU 12
macOS, FreeBSD 11
NetBSD 11 (-g 10 -w 11)
OpenBSD 11
AIX, Solaris 12
So, the BSD implementations don't count the newline.