GCC Code Coverage Report


Directory: ./
File: src/line-editing/termios.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 3 15 20.0%
Functions: 1 3 33.3%
Branches: 1 4 25.0%

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 1027 int disable_buffer(void)
41 {
42 struct termios term;
43
44
1/2
✓ Branch 1 taken 1027 times.
✗ Branch 2 not taken.
1027 if (tcgetattr(STDIN_FILENO, &term) == -1)
45 1027 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