| 1 |
|
| /* You may distribute under the terms of either the GNU General Public License |
| 2 |
|
| * or the Artistic License (the same terms as Perl itself) |
| 3 |
|
| * |
| 4 |
|
| * (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk |
| 5 |
|
| */ |
| 6 |
|
| |
| 7 |
|
| #include "EXTERN.h" |
| 8 |
|
| #include "perl.h" |
| 9 |
|
| #include "XSUB.h" |
| 10 |
|
| |
| 11 |
|
| /* Until GNU libc supports termios2, we'll have to go the direct approach |
| 12 |
|
| * |
| 13 |
|
| * Because of this there's some extra mess we have to account for. Namely, |
| 14 |
|
| * that <asm/termios.h> wants to provide two structs already known by this |
| 15 |
|
| * point (because "perl.h" brought them in). gcc will complain. But since we |
| 16 |
|
| * don't care about the new definitions of these new structs, we'll just throw |
| 17 |
|
| * them away. |
| 18 |
|
| */ |
| 19 |
|
| |
| 20 |
|
| #define winsize ASM_TERMIOS_winsize |
| 21 |
|
| #define termio ASM_TERMIOS_termio |
| 22 |
|
| # include <asm/termios.h> |
| 23 |
|
| # include <asm/ioctls.h> |
| 24 |
|
| #undef winsize |
| 25 |
|
| #undef termio |
| 26 |
|
| |
| 27 |
|
| typedef struct termios2 *Linux__Termios2; |
| 28 |
|
| |
| 29 |
|
| MODULE = Linux::Termios2 PACKAGE = Linux::Termios2 |
| 30 |
|
| |
| 31 |
|
| Linux::Termios2 |
| 32 |
|
| new(package) |
| 33 |
|
| char *package |
| 34 |
|
| CODE: |
| 35 |
0 |
| Newx(RETVAL, 1, struct termios2); |
| 36 |
|
| OUTPUT: |
| 37 |
|
| RETVAL |
| 38 |
|
| |
| 39 |
|
| void |
| 40 |
|
| DESTROY(self) |
| 41 |
|
| Linux::Termios2 self |
| 42 |
|
| CODE: |
| 43 |
0 |
| Safefree(self); |
| 44 |
|
| |
| 45 |
|
| void |
| 46 |
|
| getattr(self, fd) |
| 47 |
|
| Linux::Termios2 self |
| 48 |
|
| int fd |
| 49 |
|
| PPCODE: |
| 50 |
0 |
▶ | if(ioctl(fd, TCGETS2, self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(ioctl(fd, TCGETS2, self)) |
0 |
0 |
0 |
|
| 51 |
0 |
| XSRETURN_UNDEF; |
| 52 |
|
| |
| 53 |
0 |
| ST(0) = &PL_sv_yes; |
| 54 |
0 |
| XSRETURN(1); |
| 55 |
|
| |
| 56 |
|
| void |
| 57 |
|
| setattr(self, fd, act) |
| 58 |
|
| Linux::Termios2 self |
| 59 |
|
| int fd |
| 60 |
|
| int act |
| 61 |
|
| PPCODE: |
| 62 |
|
| { |
| 63 |
|
| int ctl; |
| 64 |
0 |
| switch(act) { |
| 65 |
0 |
| case TCSANOW: ctl = TCSETS2; break; |
| 66 |
0 |
| case TCSADRAIN: ctl = TCSETSW2; break; |
| 67 |
0 |
| case TCSAFLUSH: ctl = TCSETSF2; break; |
| 68 |
0 |
| default: |
| 69 |
0 |
| SETERRNO(EINVAL, LIB_INVARG); |
| 70 |
0 |
| XSRETURN_UNDEF; |
| 71 |
|
| } |
| 72 |
0 |
▶ | if(ioctl(fd, ctl, self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(ioctl(fd, ctl, self)) |
0 |
0 |
0 |
|
| 73 |
0 |
| XSRETURN_UNDEF; |
| 74 |
|
| |
| 75 |
0 |
| ST(0) = &PL_sv_yes; |
| 76 |
0 |
| XSRETURN(1); |
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
|
| int |
| 80 |
|
| getcflag(self) |
| 81 |
|
| Linux::Termios2 self |
| 82 |
|
| ALIAS: |
| 83 |
|
| getcflag = 0 |
| 84 |
|
| getiflag = 1 |
| 85 |
|
| getlflag = 2 |
| 86 |
|
| getoflag = 3 |
| 87 |
|
| getispeed = 4 |
| 88 |
|
| getospeed = 5 |
| 89 |
|
| CODE: |
| 90 |
0 |
| switch(ix) { |
| 91 |
0 |
| case 0: RETVAL = self->c_cflag; break; |
| 92 |
0 |
| case 1: RETVAL = self->c_iflag; break; |
| 93 |
0 |
| case 2: RETVAL = self->c_lflag; break; |
| 94 |
0 |
| case 3: RETVAL = self->c_oflag; break; |
| 95 |
0 |
| case 4: RETVAL = self->c_ispeed; break; |
| 96 |
0 |
| case 5: RETVAL = self->c_ospeed; break; |
| 97 |
|
| } |
| 98 |
|
| OUTPUT: |
| 99 |
|
| RETVAL |
| 100 |
|
| |
| 101 |
|
| void |
| 102 |
|
| setcflag(self, val) |
| 103 |
|
| Linux::Termios2 self |
| 104 |
|
| int val |
| 105 |
|
| ALIAS: |
| 106 |
|
| setcflag = 0 |
| 107 |
|
| setiflag = 1 |
| 108 |
|
| setlflag = 2 |
| 109 |
|
| setoflag = 3 |
| 110 |
|
| CODE: |
| 111 |
0 |
| switch(ix) { |
| 112 |
0 |
| case 0: self->c_cflag = val; break; |
| 113 |
0 |
| case 1: self->c_iflag = val; break; |
| 114 |
0 |
| case 2: self->c_lflag = val; break; |
| 115 |
0 |
| case 3: self->c_oflag = val; break; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
|
| void |
| 119 |
|
| setispeed(self, val) |
| 120 |
|
| Linux::Termios2 self |
| 121 |
|
| int val |
| 122 |
|
| ALIAS: |
| 123 |
|
| setispeed = 0 |
| 124 |
|
| setospeed = 1 |
| 125 |
|
| CODE: |
| 126 |
0 |
| switch(ix) { |
| 127 |
0 |
| case 0: self->c_ispeed = val; break; |
| 128 |
0 |
| case 1: self->c_ospeed = val; break; |
| 129 |
|
| } |
| 130 |
0 |
| self->c_cflag &= ~CBAUD; |
| 131 |
0 |
| self->c_cflag |= BOTHER; |