-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunalias.c
More file actions
42 lines (37 loc) · 672 Bytes
/
unalias.c
File metadata and controls
42 lines (37 loc) · 672 Bytes
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
#include "shell.h"
/**
* remove_alias - remove node with key from linked list
* @head: first node
* @key: token key of node to remove
*
* Return: 0 on sucess -1 on faliure
*/
int remove_alias(alias **head, char *key)
{
alias *_head, *tmp;
if (!*head)
return (-1);
if (!_strcmp((*head)->key, key))
{
_head = *head;
*head = (*head)->next;
free(_head->key);
free(_head->value);
free(_head);
return (0);
}
_head = *head;
while (_head->next)
{
if (!_strcmp(_head->next->key, key))
{
tmp = _head->next;
_head->next = _head->next->next;
free(tmp->key);
free(tmp->value);
free(tmp);
}
_head = _head->next;
}
return (0);
}