OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / prebuilt / ndk / android-ndk-r4 / platforms / android-8 / arch-x86 / usr / include / termios.h
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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
13  *    distribution.
14  *
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
26  * SUCH DAMAGE.
27  */
28 #ifndef _TERMIOS_H_
29 #define _TERMIOS_H_
30
31 #include <sys/cdefs.h>
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
34 #include <stdint.h>
35 #include <linux/termios.h>
36
37 __BEGIN_DECLS
38
39 /* Redefine these to match their ioctl number */
40 #undef  TCSANOW
41 #define TCSANOW    TCSETS
42
43 #undef  TCSADRAIN
44 #define TCSADRAIN  TCSETSW
45
46 #undef  TCSAFLUSH
47 #define TCSAFLUSH  TCSETSF
48
49 static __inline__ int tcgetattr(int fd, struct termios *s)
50 {
51     return ioctl(fd, TCGETS, s);
52 }
53
54 static __inline__ int tcsetattr(int fd, int __opt, const struct termios *s)
55 {
56     return ioctl(fd, __opt, (void *)s);
57 }
58
59 static __inline__ int tcflow(int fd, int action)
60 {
61     return ioctl(fd, TCXONC, (void *)(intptr_t)action);
62 }
63
64 static __inline__ int tcflush(int fd, int __queue)
65 {
66     return ioctl(fd, TCFLSH, (void *)(intptr_t)__queue);
67 }
68
69 static __inline__ pid_t tcgetsid(int fd)
70 {
71     pid_t _pid;
72     return ioctl(fd, TIOCGSID, &_pid) ? (pid_t)-1 : _pid;
73 }
74
75 static __inline__ int tcsendbreak(int fd, int __duration)
76 {
77     return ioctl(fd, TCSBRKP, (void *)(uintptr_t)__duration);
78 }
79
80 static __inline__ speed_t cfgetospeed(const struct termios *s)
81 {
82     return (speed_t)(s->c_cflag & CBAUD);
83 }
84
85 static __inline__ int cfsetospeed(struct termios *s, speed_t  speed)
86 {
87     s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
88     return 0;
89 }
90
91 static __inline__ speed_t cfgetispeed(const struct termios *s)
92 {
93     return (speed_t)(s->c_cflag & CBAUD);
94 }
95
96 static __inline__ int cfsetispeed(struct termios *s, speed_t  speed)
97 {
98     s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
99   return 0;
100 }
101
102 static __inline__ void cfmakeraw(struct termios *s)
103 {
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);
108     s->c_cflag |= CS8;
109 }
110
111 __END_DECLS
112
113 #endif /* _TERMIOS_H_ */