Fix error reporting to conform to the POSIX ttyname_r and ttyname.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29917 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
909dad39fb
commit
80e1f0e419
@ -29,15 +29,15 @@ ttyname_r(int fd, char *buffer, size_t bufferSize)
|
||||
|
||||
// first, some sanity checks:
|
||||
if (fstat(fd, &fdStat) < 0)
|
||||
return -1;
|
||||
|
||||
if (!S_ISCHR(fdStat.st_mode) || !isatty(fd)) {
|
||||
errno = ENOTTY;
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
if (!S_ISCHR(fdStat.st_mode) || !isatty(fd))
|
||||
return ENOTTY;
|
||||
|
||||
// just ask devfs
|
||||
return ioctl(fd, B_GET_PATH_FOR_DEVICE, buffer, bufferSize);
|
||||
if (ioctl(fd, B_GET_PATH_FOR_DEVICE, buffer, bufferSize) < 0)
|
||||
return errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +52,9 @@ ttyname(int fd)
|
||||
static char pathname[MAXPATHLEN];
|
||||
|
||||
int err = ttyname_r(fd, pathname, sizeof(pathname));
|
||||
if (err < 0)
|
||||
if (err != 0) {
|
||||
errno = err;
|
||||
return NULL;
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user