I think the diff should do only one thing:
-w width
Print a maximum of width characters on each line. The default is
130 characters.
At startup, do the ioctl to get the width. If -w is specified, it
overrides thae value.
And delete the sentence about 130 from the manual page.
Rather than writing completely new code from scratch with it's own quirks,
find and copy other utilities which already does it fully, such as
ls, ps, sed, column, w, etc
There's no need to be unique snowflake with subtly different behaviour.
It would be a better world if they all behaved precisely the same rather
than some hodgepodge of new code doing it in yet another subtly
different way. The majority of them evaluate the width choices in this
way, and it would be great if there was further convergence towards
this, instead of needless divergence.
if ((p = getenv("COLUMNS")) != NULL)
termwidth = strtonum(p, 1, INT_MAX, NULL);
if (termwidth == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
win.ws_col > 0)
termwidth = win.ws_col;
if (termwidth == 0)
termwidth = 80;