2 * Copyright (C) 2008 The Android Open Source Project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
35 #include <linux/termios.h>
39 /* Redefine these to match their ioctl number */
41 #define TCSANOW TCSETS
44 #define TCSADRAIN TCSETSW
47 #define TCSAFLUSH TCSETSF
49 static __inline__
int tcgetattr(int fd
, struct termios
*s
)
51 return ioctl(fd
, TCGETS
, s
);
54 static __inline__
int tcsetattr(int fd
, int __opt
, const struct termios
*s
)
56 return ioctl(fd
, __opt
, (void *)s
);
59 static __inline__
int tcflow(int fd
, int action
)
61 return ioctl(fd
, TCXONC
, (void *)(intptr_t)action
);
64 static __inline__
int tcflush(int fd
, int __queue
)
66 return ioctl(fd
, TCFLSH
, (void *)(intptr_t)__queue
);
69 static __inline__ pid_t
tcgetsid(int fd
)
72 return ioctl(fd
, TIOCGSID
, &_pid
) ? (pid_t
)-1 : _pid
;
75 static __inline__
int tcsendbreak(int fd
, int __duration
)
77 return ioctl(fd
, TCSBRKP
, (void *)(uintptr_t)__duration
);
80 static __inline__ speed_t
cfgetospeed(const struct termios
*s
)
82 return (speed_t
)(s
->c_cflag
& CBAUD
);
85 static __inline__
int cfsetospeed(struct termios
*s
, speed_t speed
)
87 s
->c_cflag
= (s
->c_cflag
& ~CBAUD
) | (speed
& CBAUD
);
91 static __inline__ speed_t
cfgetispeed(const struct termios
*s
)
93 return (speed_t
)(s
->c_cflag
& CBAUD
);
96 static __inline__
int cfsetispeed(struct termios
*s
, speed_t speed
)
98 s
->c_cflag
= (s
->c_cflag
& ~CBAUD
) | (speed
& CBAUD
);
102 static __inline__
void cfmakeraw(struct termios
*s
)
104 s
->c_iflag
&= ~(IGNBRK
|BRKINT
|PARMRK
|ISTRIP
|INLCR
|IGNCR
|ICRNL
|IXON
);
105 s
->c_oflag
&= ~OPOST
;
106 s
->c_lflag
&= ~(ECHO
|ECHONL
|ICANON
|ISIG
|IEXTEN
);
107 s
->c_cflag
&= ~(CSIZE
|PARENB
);
113 #endif /* _TERMIOS_H_ */