util: properly detect ttyname_r() failing

This commit is contained in:
Lennart Poettering 2010-08-16 21:25:09 +02:00
parent 116205924e
commit 618e02c7b7
1 changed files with 3 additions and 2 deletions

View File

@ -2531,11 +2531,12 @@ char* getlogname_malloc(void) {
int getttyname_malloc(char **r) {
char path[PATH_MAX], *p, *c;
int k;
assert(r);
if (ttyname_r(STDIN_FILENO, path, sizeof(path)) < 0)
return -errno;
if ((k = ttyname_r(STDIN_FILENO, path, sizeof(path))) != 0)
return -k;
char_array_0(path);