-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexitlink.c
More file actions
55 lines (46 loc) · 856 Bytes
/
exitlink.c
File metadata and controls
55 lines (46 loc) · 856 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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "shell.h"
/**
* sh_free_double_ptr - free malloced arrays
* @s: string
*
*/
void sh_free_double_ptr(char **s)
{
int j = 0;
while (s[j] != NULL)
{
free(s[j]);
j++;
}
free(s);
}
/**
* illegal_n - print error
* @s: string
* @cmd: typed command
* @env: environment
*/
void illegal_n(char *s, int cmd, list_t **env)
{
int sum = 0;
char *hsh = NULL, *number = NULL;
hsh = h_getenv("_", env);
while (hsh[sum] != '\0')
sum++;
write(STDOUT_FILENO, hsh, sum);
free(hsh);
write(STDOUT_FILENO, ": ", 2);
number = int_string(cmd);
sum = 0;
while (number[sum] != '\0')
sum++;
write(STDOUT_FILENO, number, sum);
free(number);
write(STDOUT_FILENO, ": ", 2);
write(STDOUT_FILENO, "exit: illegal number: ", 22);
sum = 0;
while (s[sum] != '\0')
sum++;
write(STDOUT_FILENO, s, sum);
write(STDOUT_FILENO, "\n", 1);
}