Add TTY(RawFD) for non-STDIO tty's

Also add the necessary c functions to extract the FD/Handle from a pipe object. These aren't used anywhere, but will be helpful for #3823