linux ttyname and ttyname_r: do not return wrong results