Skip to content

Commit 25fbc06

Browse files
committed
replace ioctl syscalls with internal ioctl
1 parent e749455 commit 25fbc06

File tree

8 files changed

+19
-49
lines changed

8 files changed

+19
-49
lines changed

libc/src/termios/linux/tcdrain.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
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-
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;
23+
return LIBC_NAMESPACE::ioctl(fd, TCSBRK, 1);
2924
}
3025

3126
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcflow.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
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-
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;
23+
return LIBC_NAMESPACE::ioctl(fd, TCXONC, action);
2924
}
3025

3126
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcflush.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@
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-
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;
23+
return LIBC_NAMESPACE::ioctl(fd, TCFLSH, queue_selector);
3024
}
3125

3226
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcgetattr.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
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::syscall_impl<int>(SYS_ioctl, fd, TCGETS, &kt);
26-
if (ret < 0) {
27-
libc_errno = -ret;
25+
int ret = LIBC_NAMESPACE::ioctl(fd, TCGETS, &kt);
26+
if (ret < 0)
2827
return -1;
29-
}
28+
3029
t->c_iflag = kt.c_iflag;
3130
t->c_oflag = kt.c_oflag;
3231
t->c_cflag = kt.c_cflag;

libc/src/termios/linux/tcgetsid.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@
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::syscall_impl<int>(SYS_ioctl, fd, TIOCGSID, &sid);
25-
if (ret < 0) {
26-
libc_errno = -ret;
24+
int ret = LIBC_NAMESPACE::ioctl(fd, TIOCGSID, &sid);
25+
if (ret < 0)
2726
return -1;
28-
}
27+
2928
return sid;
3029
}
3130

libc/src/termios/linux/tcsendbreak.cpp

Lines changed: 2 additions & 7 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,12 +23,7 @@ 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-
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;
26+
return LIBC_NAMESPACE::ioctl(SYS_ioctl, fd, TCSBRK, 0);
3227
}
3328

3429
} // namespace LIBC_NAMESPACE_DECL

libc/src/termios/linux/tcsetattr.cpp

Lines changed: 2 additions & 7 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,12 +52,7 @@ LLVM_LIBC_FUNCTION(int, tcsetattr,
5252
kt.c_cc[i] = 0;
5353
}
5454

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;
55+
return LIBC_NAMESPACE::ioctl(fd, cmd, &kt);
6156
}
6257

6358
} // namespace LIBC_NAMESPACE_DECL

libc/src/unistd/linux/isatty.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ 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 =
27-
LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, TIOCGETD, &line_d_val);
26+
int result = LIBC_NAMESPACE::ioctl(fd, TIOCGETD, &line_d_val);
2827
if (result == 0)
2928
return 1;
3029

31-
libc_errno = -result;
3230
return 0;
3331
}
3432

0 commit comments

Comments
 (0)