| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 |  | 
| Vitaly Wool | 9549238 | 2012-09-04 14:11:28 +0200 | [diff] [blame] | 69 | static __inline__ int tcdrain(int fd) | 
|  | 70 | { | 
|  | 71 | return ioctl(fd, TCSBRK, (void *)(intptr_t)1); | 
|  | 72 | } | 
|  | 73 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 74 | static __inline__ pid_t tcgetsid(int fd) | 
|  | 75 | { | 
|  | 76 | pid_t _pid; | 
|  | 77 | return ioctl(fd, TIOCGSID, &_pid) ? (pid_t)-1 : _pid; | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | static __inline__ int tcsendbreak(int fd, int __duration) | 
|  | 81 | { | 
|  | 82 | return ioctl(fd, TCSBRKP, (void *)(uintptr_t)__duration); | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | static __inline__ speed_t cfgetospeed(const struct termios *s) | 
|  | 86 | { | 
|  | 87 | return (speed_t)(s->c_cflag & CBAUD); | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | static __inline__ int cfsetospeed(struct termios *s, speed_t  speed) | 
|  | 91 | { | 
|  | 92 | s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD); | 
|  | 93 | return 0; | 
|  | 94 | } | 
|  | 95 |  | 
|  | 96 | static __inline__ speed_t cfgetispeed(const struct termios *s) | 
|  | 97 | { | 
|  | 98 | return (speed_t)(s->c_cflag & CBAUD); | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | static __inline__ int cfsetispeed(struct termios *s, speed_t  speed) | 
|  | 102 | { | 
|  | 103 | s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD); | 
|  | 104 | return 0; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | static __inline__ void cfmakeraw(struct termios *s) | 
|  | 108 | { | 
|  | 109 | s->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); | 
|  | 110 | s->c_oflag &= ~OPOST; | 
|  | 111 | s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); | 
|  | 112 | s->c_cflag &= ~(CSIZE|PARENB); | 
|  | 113 | s->c_cflag |= CS8; | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | __END_DECLS | 
|  | 117 |  | 
|  | 118 | #endif /* _TERMIOS_H_ */ |