forked from ygrek/extunix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtty_ioctl.c
50 lines (41 loc) · 1.09 KB
/
tty_ioctl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright : (c) 2010, Stéphane Glondu <[email protected]>
*/
#define EXTUNIX_WANT_TTY_IOCTL
#include "config.h"
#if defined(EXTUNIX_HAVE_TTY_IOCTL)
/* FIXME implement separate interface for tcsetattr/tcgetattr */
CAMLprim value caml_extunix_crtscts(value mlfd)
{
CAMLparam1(mlfd);
struct termios t;
int r, fd = Int_val(mlfd);
r = tcgetattr(fd, &t);
if (0 == r) {
t.c_cflag |= CRTSCTS;
r = tcsetattr(fd, TCSANOW, &t);
}
if (0 != r) uerror("crtscts",Nothing);
CAMLreturn(Val_unit);
}
#define TTY_IOCTL_INT(cmd) \
CAMLprim value caml_extunix_ioctl_##cmd(value v_fd, value v_arg) \
{ \
CAMLparam2(v_fd, v_arg); \
int arg = Int_val(v_arg); \
int r = ioctl(Int_val(v_fd), cmd, &arg); \
if (r < 0) uerror("ioctl",caml_copy_string(#cmd)); \
CAMLreturn(Val_unit); \
}
CAMLprim value caml_extunix_ioctl_TIOCMGET(value v_fd)
{
CAMLparam1(v_fd);
int arg = 0;
int r = ioctl(Int_val(v_fd), TIOCMGET, &arg);
if (r < 0) uerror("ioctl",caml_copy_string("TIOCMGET"));
CAMLreturn(Val_int(arg));
}
TTY_IOCTL_INT(TIOCMSET)
TTY_IOCTL_INT(TIOCMBIC)
TTY_IOCTL_INT(TIOCMBIS)
#endif