chiark / gitweb /
util.c: check if return value from ttyname_r is > 0 instead of != 0
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sat, 30 Nov 2013 22:45:31 +0000 (23:45 +0100)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Sat, 30 Nov 2013 23:14:28 +0000 (00:14 +0100)
We must return a negative error code from getttyname_malloc but
that would not be the case if ttyname_r returned a negative value.

ttyname_r should only return EBADF, ENOTTY, or ERANGE so it should
be safe to change.

src/shared/util.c

index 38134ae521b61963de65667dc7920dffc9d9bf32..206fc803d0e8b3f04a50fd0baf5cea1ff1a00f5c 100644 (file)
@@ -2501,7 +2501,7 @@ int getttyname_malloc(int fd, char **r) {
         assert(r);
 
         k = ttyname_r(fd, path, sizeof(path));
-        if (k != 0)
+        if (k > 0)
                 return -k;
 
         char_array_0(path);