(((buf[idx] == '\n') && ((idx == 0) || (buf[idx-1] != '\r'))) || (buf[idx] == '\r'))
Handling three types of line endings requires one character of look-back. And with one character of look-back, you have to make sure you don't look at index -1 if the first character is a LF. That's complicated stuff for the poor new hire that has to work on the default text editor. Look at all those parenthesis! I don't even know if I got it right. Now, 33 years later, there's Stack Overflow.