-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaliases2.c
59 lines (52 loc) · 958 Bytes
/
aliases2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "shell.h"
/**
* check_alias - checks if a command is an alias
* @shell: pointer to shell structure
*
* Return: void
*/
void check_alias(sh_data *shell)
{
alias_l *temp = shell->alias;
int i, j, len;
char *command;
while (temp)
{
if (my_strcmp(temp->name, shell->arr[0]) == 0)
{
len = my_strlen(temp->value);
command = malloc(sizeof(char) * (len - 1));
for (i = 1, j = 0; i < len - 1; i++, j++)
command[j] = temp->value[i];
command[j] = '\0';
free(shell->arr[0]);
shell->arr[0] = command;
break;
}
temp = temp->next;
}
}
/**
* free_aliases - frees the alias_l linked list
* @head: pointer to the list
*
* Return: non
*/
void free_aliases(alias_l *head)
{
alias_l *temp = head, *second;
if (head)
{
while (temp->next)
{
second = temp;
temp = temp->next;
free(second->name);
free(second->value);
free(second);
}
free(temp->name);
free(temp->value);
free(temp);
}
}