GCC Code Coverage Report


Directory: ./
File: src/builtins/unset.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 11 13 84.6%
Functions: 2 2 100.0%
Branches: 7 8 87.5%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** 42sh
4 ** File description:
5 ** The file containing the unset builtin
6 */
7 /**
8 * @file unset.c
9 * @brief The file containing the unset builtin
10 */
11
12 #include "../../include/myshell.h"
13
14 /**
15 * @brief Remove a variable from the variable list
16 * @param mysh The shell structure
17 * @param index The index of the variable to remove
18 * @return <b>void</b>
19 */
20 20 static void unset_variable(mysh_t *mysh, int index)
21 {
22
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 12 times.
67 for (node_t *tmp = mysh->variable_list; tmp != NULL; tmp = tmp->next) {
23
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 47 times.
55 if (my_strcmp(((variable_t *)tmp->data)->name,
24 55 mysh->args[index]) == 0) {
25 8 my_free_ptr(my_previous_to_next(&mysh->variable_list, tmp));
26 8 return;
27 }
28 }
29 }
30
31 /**
32 * @brief The unset builtin
33 * @param mysh The shell structure
34 * @return <b>int</b> <u>0</u> if the command succeed, <u>1</u> otherwise
35 */
36 10 int exec_unset(mysh_t *mysh)
37 {
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (mysh->args[1] == NULL) {
39 my_putstr_error("unset: Too few arguments.\n");
40 return 1;
41 }
42
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
30 for (int index = 0; mysh->args[index] != NULL; index++)
43 20 unset_variable(mysh, index);
44 10 return 0;
45 }
46