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 | */ |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 28 | |
| 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file termios.h |
| 33 | * @brief General terminal interfaces. |
| 34 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | |
| 36 | #include <sys/cdefs.h> |
| 37 | #include <sys/ioctl.h> |
| 38 | #include <sys/types.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | #include <linux/termios.h> |
| 40 | |
| 41 | __BEGIN_DECLS |
| 42 | |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 43 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 44 | // This file is implemented as static inlines before API level 21. |
| 45 | |
| 46 | /** |
| 47 | * [cfgetispeed(3)](http://man7.org/linux/man-pages/man3/cfgetispeed.3.html) |
| 48 | * returns the terminal input baud rate. |
| 49 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 50 | speed_t cfgetispeed(const struct termios* __t) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 51 | |
| 52 | /** |
| 53 | * [cfgetospeed(3)](http://man7.org/linux/man-pages/man3/cfgetospeed.3.html) |
| 54 | * returns the terminal output baud rate. |
| 55 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 56 | speed_t cfgetospeed(const struct termios* __t) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 57 | |
| 58 | /** |
| 59 | * [cfmakeraw(3)](http://man7.org/linux/man-pages/man3/cfmakeraw.3.html) |
| 60 | * configures the terminal for "raw" mode. |
| 61 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 62 | void cfmakeraw(struct termios* __t) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 63 | |
| 64 | /** |
| 65 | * [cfsetspeed(3)](http://man7.org/linux/man-pages/man3/cfsetspeed.3.html) |
| 66 | * sets the terminal input and output baud rate. |
| 67 | * |
| 68 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 69 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 70 | int cfsetspeed(struct termios* __t, speed_t __speed) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 71 | |
| 72 | /** |
| 73 | * [cfsetispeed(3)](http://man7.org/linux/man-pages/man3/cfsetispeed.3.html) |
| 74 | * sets the terminal input baud rate. |
| 75 | * |
| 76 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 77 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 78 | int cfsetispeed(struct termios* __t, speed_t __speed) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 79 | |
| 80 | /** |
| 81 | * [cfsetospeed(3)](http://man7.org/linux/man-pages/man3/cfsetospeed.3.html) |
| 82 | * sets the terminal output baud rate. |
| 83 | * |
| 84 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 85 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 86 | int cfsetospeed(struct termios* __t, speed_t __speed) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 87 | |
| 88 | /** |
| 89 | * [tcdrain(3)](http://man7.org/linux/man-pages/man3/tcdrain.3.html) |
| 90 | * waits until all output has been written. |
| 91 | * |
| 92 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 93 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 94 | int tcdrain(int __fd) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 95 | |
| 96 | /** |
| 97 | * [tcflow(3)](http://man7.org/linux/man-pages/man3/tcflow.3.html) |
| 98 | * suspends (`TCOOFF`) or resumes (`TCOON`) output, or transmits a |
| 99 | * stop (`TCIOFF`) or start (`TCION`) to suspend or resume input. |
| 100 | * |
| 101 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 102 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 103 | int tcflow(int __fd, int __action) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 104 | |
| 105 | /** |
| 106 | * [tcflush(3)](http://man7.org/linux/man-pages/man3/tcflush.3.html) |
| 107 | * discards pending input (`TCIFLUSH`), output (`TCOFLUSH`), or |
| 108 | * both (`TCIOFLUSH`). (In `<stdio.h>` terminology, this is a purge rather |
| 109 | * than a flush.) |
| 110 | * |
| 111 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 112 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 113 | int tcflush(int __fd, int __queue) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 114 | |
| 115 | /** |
| 116 | * [tcgetattr(3)](http://man7.org/linux/man-pages/man3/tcgetattr.3.html) |
| 117 | * reads the configuration of the given terminal. |
| 118 | * |
| 119 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 120 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 121 | int tcgetattr(int __fd, struct termios* __t) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 122 | |
| 123 | /** |
| 124 | * [tcgetsid(3)](http://man7.org/linux/man-pages/man3/tcgetsid.3.html) |
| 125 | * returns the session id corresponding to the given fd. |
| 126 | * |
| 127 | * Returns a non-negative session id on success and |
| 128 | * returns -1 and sets `errno` on failure. |
| 129 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 130 | pid_t tcgetsid(int __fd) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 131 | |
| 132 | /** |
| 133 | * [tcsendbreak(3)](http://man7.org/linux/man-pages/man3/tcsendbreak.3.html) |
| 134 | * sends a break. |
| 135 | * |
| 136 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 137 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 138 | int tcsendbreak(int __fd, int __duration) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 139 | |
| 140 | /** |
| 141 | * [tcsetattr(3)](http://man7.org/linux/man-pages/man3/tcsetattr.3.html) |
| 142 | * writes the configuration of the given terminal. |
| 143 | * |
| 144 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 145 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 146 | int tcsetattr(int __fd, int __optional_actions, const struct termios* __t) __INTRODUCED_IN(21); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame^] | 147 | |
Josh Gao | 8778d64 | 2016-07-22 15:26:36 -0700 | [diff] [blame] | 148 | #endif |
| 149 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 150 | __END_DECLS |
| 151 | |
Josh Gao | b8e1b705 | 2016-04-13 17:18:20 -0700 | [diff] [blame] | 152 | #include <android/legacy_termios_inlines.h> |