Monday, 23 November 2009

Cooked linux console

Recently while I was playing around with code, there was a log line
printf("foo: skipped '%c'\n", c);

When c was a carriage return; the log line obtained was
'oo: skipped '
This was because carriage return takes the current position to the beginning of the line. Now, as the linux console is cooked by default [Most *nix programs get their tty input via the kernel tty driver in `cooked' mode.], it formatted the whole line and printed the line at once producing the effect.

A simple way to detect parts where the "cooked" console interferes is to run the command from within emacs. Emacs does its own input handling and is not cooked. The same log line in emacs is shown as:
foo: skipped '^M'

These petty issues must be kept in mind while considering portability of software.

No comments: