Skip to content

Commit 8083813

Browse files
committed
Revert "replace ioctl syscalls with internal ioctl"
This reverts commit 25fbc06.
1 parent 25fbc06 commit 8083813

File tree

8 files changed

+49
-19
lines changed

8 files changed

+49
-19
lines changed

libc/src/termios/linux/tcdrain.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
1515

16-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
16+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1717
#include <sys/syscall.h> // For syscall numbers
1818
#include <termios.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

2222
LLVM_LIBC_FUNCTION(int, tcdrain, (int fd)) {
23-
return LIBC_NAMESPACE::ioctl(fd, TCSBRK, 1);
23+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TCSBRK, 1);
24+
if (ret < 0) {
25+
libc_errno = -ret;
26+
return -1;
27+
}
28+
return 0;
2429
}
2530

2631
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcflow.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
1515

16-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
16+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1717
#include <sys/syscall.h> // For syscall numbers
1818
#include <termios.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

2222
LLVM_LIBC_FUNCTION(int, tcflow, (int fd, int action)) {
23-
return LIBC_NAMESPACE::ioctl(fd, TCXONC, action);
23+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TCXONC, action);
24+
if (ret < 0) {
25+
libc_errno = -ret;
26+
return -1;
27+
}
28+
return 0;
2429
}
2530

2631
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcflush.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
1515

16-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
16+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1717
#include <sys/syscall.h> // For syscall numbers
1818
#include <termios.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

2222
LLVM_LIBC_FUNCTION(int, tcflush, (int fd, int queue_selector)) {
23-
return LIBC_NAMESPACE::ioctl(fd, TCFLSH, queue_selector);
23+
int ret =
24+
LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TCFLSH, queue_selector);
25+
if (ret < 0) {
26+
libc_errno = -ret;
27+
return -1;
28+
}
29+
return 0;
2430
}
2531

2632
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcgetattr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
#include "src/__support/macros/config.h"
1515
#include "src/errno/libc_errno.h"
1616

17-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
17+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1818
#include <sys/syscall.h> // For syscall numbers
1919
#include <termios.h>
2020

2121
namespace LIBC_NAMESPACE_DECL {
2222

2323
LLVM_LIBC_FUNCTION(int, tcgetattr, (int fd, struct termios *t)) {
2424
LIBC_NAMESPACE::kernel_termios kt;
25-
int ret = LIBC_NAMESPACE::ioctl(fd, TCGETS, &kt);
26-
if (ret < 0)
25+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TCGETS, &kt);
26+
if (ret < 0) {
27+
libc_errno = -ret;
2728
return -1;
28-
29+
}
2930
t->c_iflag = kt.c_iflag;
3031
t->c_oflag = kt.c_oflag;
3132
t->c_cflag = kt.c_cflag;

libc/src/termios/linux/tcgetsid.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
1515

16-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
16+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1717
#include <sys/syscall.h> // For syscall numbers
1818
#include <termios.h>
1919

2020
namespace LIBC_NAMESPACE_DECL {
2121

2222
LLVM_LIBC_FUNCTION(pid_t, tcgetsid, (int fd)) {
2323
pid_t sid;
24-
int ret = LIBC_NAMESPACE::ioctl(fd, TIOCGSID, &sid);
25-
if (ret < 0)
24+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TIOCGSID, &sid);
25+
if (ret < 0) {
26+
libc_errno = -ret;
2627
return -1;
27-
28+
}
2829
return sid;
2930
}
3031

libc/src/termios/linux/tcsendbreak.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "src/__support/macros/config.h"
1414
#include "src/errno/libc_errno.h"
1515

16-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
16+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1717
#include <sys/syscall.h> // For syscall numbers
1818
#include <termios.h>
1919

@@ -23,7 +23,12 @@ LLVM_LIBC_FUNCTION(pid_t, tcsendbreak, (int fd, int /* unused duration */)) {
2323
// POSIX leaves the behavior for non-zero duration implementation dependent.
2424
// Which means that the behavior can be the same as it is when duration is
2525
// zero. So, we just pass zero to the syscall.
26-
return LIBC_NAMESPACE::ioctl(SYS_ioctl, fd, TCSBRK, 0);
26+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TCSBRK, 0);
27+
if (ret < 0) {
28+
libc_errno = -ret;
29+
return -1;
30+
}
31+
return 0;
2732
}
2833

2934
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcsetattr.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "src/__support/macros/config.h"
1515
#include "src/errno/libc_errno.h"
1616

17-
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
17+
#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
1818
#include <sys/syscall.h> // For syscall numbers
1919
#include <termios.h>
2020

@@ -52,7 +52,12 @@ LLVM_LIBC_FUNCTION(int, tcsetattr,
5252
kt.c_cc[i] = 0;
5353
}
5454

55-
return LIBC_NAMESPACE::ioctl(fd, cmd, &kt);
55+
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, cmd, &kt);
56+
if (ret < 0) {
57+
libc_errno = -ret;
58+
return -1;
59+
}
60+
return 0;
5661
}
5762

5863
} // namespace LIBC_NAMESPACE_DECL

libc/src/unistd/linux/isatty.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ LLVM_LIBC_FUNCTION(int, isatty, (int fd)) {
2323
int line_d_val = INIT_VAL;
2424
// This gets the line dicipline of the terminal. When called on something that
2525
// isn't a terminal it doesn't change line_d_val and returns -1.
26-
int result = LIBC_NAMESPACE::ioctl(fd, TIOCGETD, &line_d_val);
26+
int result =
27+
LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TIOCGETD, &line_d_val);
2728
if (result == 0)
2829
return 1;
2930

31+
libc_errno = -result;
3032
return 0;
3133
}
3234

0 commit comments

Comments
 (0)