According to POSIX General Terminal Interface about carriage return processing:
CR
Special character on input, which is recognized if the ICANON flag is set; it is the carriage-return character. When ICANON and ICRNL are set and IGNCR is not set, this character shall be translated into an NL, and shall have the same effect as an NL character.
However, it appears that in linux, the CR is converted to a LF, even when in non canonical mode.
This can be seen by running this code and typing in a, enter, b, enter.
#include <unistd.h>
#include <termios.h>
int main() {
struct termios t;
tcgetattr(STDIN_FILENO, &t);
// t.c_iflag &= ~(ICRNL); // Turn off ICRNL
t.c_lflag &= ~(ECHO | ICANON); // Turn off ECHO and ICANON
tcsetattr(STDIN_FILENO, TCSANOW, &t);
char c;
while (read(STDIN_FILENO, &c, 1)) write(STDOUT_FILENO, &c, 1);
}
The output is
a
b
When ICRNL
is turned off by uncommenting the line of code, pressing enter after typing in a
changes the column to zero and keeps the row the same, so that when b
is pressed, the b
overwrites the a
. This is the expected behavior since the CR isn't converted to a LF by unsetting ICRNL
. However I would also expect this if ICRNL
is set and ICANON
is unset.