Skip to content

Commit 51499ce

Browse files
committed
fix ioctl linux interior return value documentation
1 parent 5fad00a commit 51499ce

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

libc/src/sys/ioctl/linux/ioctl.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ LLVM_LIBC_FUNCTION(int, ioctl, (int fd, unsigned long request, ...)) {
2424
LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, request, data_pointer);
2525
va_end(vargs);
2626

27-
// From `man ioctl`:
28-
// "Usually, on success zero is returned. A few ioctl() operations
29-
// use the return value as an output parameter and return a
30-
// nonnegative value on success. On error, -1 is returned, and errno
31-
// is set to indicate the error."
32-
if (ret < 0) {
33-
libc_errno = -ret;
34-
return -1;
27+
// Some ioctls can be expected to return positive values
28+
if (ret >= 0) {
29+
return ret;
3530
}
3631

37-
return ret;
32+
// If there is an error, errno is set and -1 is returned.
33+
libc_errno = -ret;
34+
return -1;
3835
}
3936

4037
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)