As explained as 4) in this e-mail: https://lists.gnu.org/archive/html/bug-gnulib/2011-08/msg00027.html
it seems like the ttyname_r function returns EINVAL when the provided buffer is too small. This doesn't seem consistent with the specifcation at: http://pubs.opengroup.org/onlinepubs/9699919799/functions/ttyname.html Instead, it seems this should be ERANGE? [ERANGE] The value of namesize is smaller than the length of the string to be returned including the terminating null character. /Simon