]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blob - libc/include/termios.h
Initial Contribution
[android-sdk/platform-bionic.git] / libc / 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_
31 #include <sys/cdefs.h>
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
34 #include <stdint.h>
35 #include <linux/termios.h>
37 __BEGIN_DECLS
39 /* Redefine these to match their ioctl number */
40 #undef  TCSANOW
41 #define TCSANOW    TCSETS
43 #undef  TCSADRAIN
44 #define TCSADRAIN  TCSETSW
46 #undef  TCSAFLUSH
47 #define TCSAFLUSH  TCSETSF
49 static __inline__ int tcgetattr(int fd, struct termios *s)
50 {
51     return ioctl(fd, TCGETS, s);
52 }
54 static __inline__ int tcsetattr(int fd, int __opt, const struct termios *s)
55 {
56     return ioctl(fd, __opt, (void *)s);
57 }
59 static __inline__ int tcflow(int fd, int action)
60 {
61     return ioctl(fd, TCXONC, (void *)(intptr_t)action);
62 }
64 static __inline__ int tcflush(int fd, int __queue)
65 {
66     return ioctl(fd, TCFLSH, (void *)(intptr_t)__queue);
67 }
69 static __inline__ pid_t tcgetpgrp(int fd)
70 {
71     pid_t _pid;
72     return ioctl(fd, TIOCGPGRP, &_pid) ? (pid_t)-1 : _pid;
73 }
75 static __inline__ int tcsetpgrp(int fd, pid_t _pid)
76 {
77     return ioctl(fd, TIOCSPGRP, &_pid);
78 }
80 static __inline__ pid_t tcgetsid(int fd)
81 {
82     pid_t _pid;
83     return ioctl(fd, TIOCGSID, &_pid) ? (pid_t)-1 : _pid;
84 }  
86 static __inline__ int tcsendbreak(int fd, int __duration)
87 {
88     return ioctl(fd, TCSBRKP, (void *)(uintptr_t)__duration);
89 }
91 static __inline__ speed_t cfgetospeed(const struct termios *s)
92 {
93     return (speed_t)(s->c_cflag & CBAUD);
94 }
96 static __inline__ int cfsetospeed(struct termios *s, speed_t  speed)
97 {
98     s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
99     return 0;
102 static __inline__ speed_t cfgetispeed(const struct termios *s)
104     return (speed_t)(s->c_cflag & CBAUD);
107 static __inline__ int cfsetispeed(struct termios *s, speed_t  speed)
109     s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
110   return 0;
113 static __inline__ void cfmakeraw(struct termios *s)
115     s->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
116     s->c_oflag &= ~OPOST;
117     s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
118     s->c_cflag &= ~(CSIZE|PARENB);
119     s->c_cflag |= CS8;
122 __END_DECLS
124 #endif /* _TERMIOS_H_ */