-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfree.c
60 lines (53 loc) · 957 Bytes
/
free.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
60
#include "shell.h"
/**
* free_error - frees alloc'd pointers following system error
* @argv: pointer to a pointer to an array of pointers
* @arg: pointer to a pointer to an array of characters
*
* Return: void.
*/
void free_error(char **argv, char *arg)
{
int i;
for (i = 0; argv[i]; i++)
free(argv[i]);
free(argv);
free(arg);
exit(EXIT_FAILURE);
}
/**
* free_tokens - frees memory allocated dynamically by tokenize()
* @ptr: pointer to allocated memory
*
* Return: void.
*/
void free_tokens(char **ptr)
{
int i;
for (i = 0; ptr[i]; i++)
free((ptr[i]));
free(ptr);
}
/**
* free_path - Frees the global variable containing the PATH environment
* variable value
*
* Return: Nothing
*/
void free_path(void)
{
if (environ != NULL)
{
size_t i = 0;
while (environ[i] != NULL)
{
if (_strncmp(environ[i], "PATH=", 5) == 0)
{
free(environ[i]);
environ[i] = NULL;
break;
}
i++;
}
}
}