chiark / gitweb /
util: properly detect ttyname_r() failing
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Aug 2010 19:25:09 +0000 (21:25 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 16 Aug 2010 19:25:09 +0000 (21:25 +0200)
src/util.c

index bc227f5..3bcce2f 100644 (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);