GCC Code Coverage Report


Directory: ./
File: src/builtins/unalias.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 0 12 0.0%
Functions: 0 2 0.0%
Branches: 0 8 0.0%

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