| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2024 | ||
| 3 | ** 42sh | ||
| 4 | ** File description: | ||
| 5 | ** The file containing the termios functions | ||
| 6 | */ | ||
| 7 | /** | ||
| 8 | * @file termios.c | ||
| 9 | * @brief The file containing the termios functions | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include "../../include/myshell.h" | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @brief Save terminal attributes | ||
| 16 | * @param saved_termios The termios structure to save the terminal attributes | ||
| 17 | * @return <b>void</b> | ||
| 18 | */ | ||
| 19 | ✗ | void save_termios(struct termios *saved_termios) | |
| 20 | { | ||
| 21 | ✗ | tcgetattr(STDIN_FILENO, saved_termios); | |
| 22 | ✗ | } | |
| 23 | |||
| 24 | /** | ||
| 25 | * @brief Restore terminal attributes | ||
| 26 | * @param saved_termios The termios structure to restore the | ||
| 27 | * terminal attributes | ||
| 28 | * @return <b>void</b> | ||
| 29 | */ | ||
| 30 | ✗ | void restore_termios(struct termios *saved_termios) | |
| 31 | { | ||
| 32 | ✗ | tcsetattr(STDIN_FILENO, TCSANOW, saved_termios); | |
| 33 | ✗ | } | |
| 34 | |||
| 35 | /** | ||
| 36 | * @brief Disable the buffer | ||
| 37 | * @note We'll need to disable the buffer when we want to my_getline | ||
| 38 | * @return <b>int</b> <u>0</u> if the buffer is disabled, <u>-1</u> otherwise | ||
| 39 | */ | ||
| 40 | 1092 | int disable_buffer(void) | |
| 41 | { | ||
| 42 | struct termios term; | ||
| 43 | |||
| 44 |
1/2✓ Branch 1 taken 1092 times.
✗ Branch 2 not taken.
|
1092 | if (tcgetattr(STDIN_FILENO, &term) == -1) |
| 45 | 1092 | return -1; | |
| 46 | ✗ | term.c_lflag &= ~(ICANON | ECHO); | |
| 47 | ✗ | term.c_cc[VMIN] = 1; | |
| 48 | ✗ | term.c_cc[VTIME] = 0; | |
| 49 | ✗ | if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) == -1) | |
| 50 | ✗ | return -1; | |
| 51 | ✗ | return 0; | |
| 52 | } | ||
| 53 |