-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.1built_func.c
58 lines (56 loc) · 1.06 KB
/
8.1built_func.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
#include "shell.h"
/**
* signalhandle - function that handle user signals
* @n: unused attribute (void)
*/
void signalhandle(int n __attribute__((unused)))
{
write(STDERR_FILENO, "\n", 1);
write(STDERR_FILENO, PROMPT, 2);
}
/**
* ctrl_c - function that handle ctrl c signal from user
* @line: command by user
*/
void ctrl_c(char *line)
{
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "\n", 1);
free(line);
exit(EXIT_SUCCESS);
}
/**
* fork_error - function that exit once fork is not done correctly
* @line: argument
* @commands: command given by user
*/
void fork_error(char *line, char **commands)
{
perror("FatalError: ");
free(line);
free_arrays(commands);
exit(EXIT_FAILURE);
}
/**
* free_arrays - function that free memory already used
* @array: memory to free
*/
void free_arrays(char **array)
{
/*int j;*/
/*int k;*/
if (array == NULL || *array == NULL)
return;
/*j = 0;*/
/*k = 0;*/
/*while (array[j])*/
/*j++;*/
/*while (k < j)*/
/*{*/
/*free(array[k]);*/
/*k++;*/
/*}*/
/*if (array[j] == NULL)*/
/*free(array[j]);*/
free(array);
}