Conditionally compile os-specific bits of termios under Linux and OSX

cc @gitfoxi

I expect this won't work in my first attempt, so please report all the compilation/test errors (preferably via gist snippets if they are too long) or any other issue you find here.

Note that you'll need [socat](http://www.dest-unreach.org/socat) to run the test suite. I think you can install it using homebrew.