If ioctl() fails get num of columns querying the terminal.

This change makes linenoise both more robust if the ioctl() fails, and
far more portable to non POSIX systems, since the ioclt() to query the
terminal was probably one of the non trivial parts to replace.

The code is inspired to Andreas Kupries commit 24186e99 on the win32
Linenoise port from Steve Bennett, but is a complete reimplementation.