-
Notifications
You must be signed in to change notification settings - Fork 1
/
clean_up.c
61 lines (55 loc) · 1019 Bytes
/
clean_up.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
61
#include "shell.h"
/**
* _atoi - This function converts string to integer
* @s: String to be converted
*
* Return: an integer
*/
int _atoi(char *s)
{
int noElements = _strlen(s), i;
int num = 0;
for (i = 0; i < noElements; i++)
{
if (!(s[i] >= 48 && s[i] <= 57))
return (-1);
num = (num * 10) + (s[i] - 48);
}
return (num);
}
/**
* __exit - This function exits the program and frees all allocated memory
* @argv: Pointer to string
* @str: Pointer to string
*/
void __exit(char **argv, char *str)
{
int status;
if (!argv[1])
status = exit_status;
else
status = _atoi(argv[1]);
if (status == -1)
{
fprintf(stderr, "./hsh: 1: exit: Illegal number: %s\n", argv[1]);
exit_status = 2;
return;
}
free(str);
free_env();
frees_tokens(aliase);
frees_tokens(argv);
exit(status);
}
/**
* free_env - This function frees memory that was allocated to the linked list
*/
void free_env(void)
{
int i;
for (i = 0; enviroment[i]; i++)
{
free(enviroment[i]);
}
free(enviroment);
}