For upstream

Special case zero in digit calculation, even zero needs one digit.

The termcap commit fixes an issue that came up with the Mac OS X fix commit. It breaks ncursesw support here, because it will check for termcap in plain curses lib and libs arguments will be -lcurses -lncursesw, resulting in linking against curses only.