Implement ttyname/ttyname_r