-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_helper.c
55 lines (51 loc) · 1.75 KB
/
error_helper.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
#include "shell.h"
/**
* error_helper - helps write all the errors
* @av: the av[0] passed to us
* @argv: thr argv[0] that is passed to us
* @to_string: the string that we want to be printed
*
* Description: so we want to print out erros with first,
* we want the path av[0] printed first followed by
* a ": " followed by the line number
* followed by the another ": " and then
* followed by the command string argv[0]
* then we want to print out a
* ": not found". cause its always an error in this function
* we moved 6 write functions from main to here
* Return: no return it is void
*/
void error_helper(char **av, char **argv, char *to_string)
{
write(STDERR_FILENO, av[0], _strlen(av[0]));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, to_string, _strlen(to_string));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, argv[0], _strlen(argv[0]));
write(STDERR_FILENO, ": not found\n", 12);
}
/**
* exit_helper - helps write exit too big errors
* @av: the av[0] passed to us
* @argv: thr argv[0] that is passed to us
* @to_string: the string that we want to be printed
*
* Description: so we want to print out erros with first,
* we want the path av[0] printed first followed by
* a ": " followed by the line number
* followed by the another ": " and then
* followed by the command string argv[0]
* then we want to print out a
* ": not found". cause its always an error in this function
* we moved 6 write functions from main to here
* Return: no return it is void
*/
void exit_helper(char **av, char **argv, char *to_string)
{
write(2, av[0], _strlen(av[0]));
write(2, ": ", 2);
write(2, to_string, _strlen(to_string));
write(2, ": exit: Illegal number: ", 24);
write(2, argv[1], _strlen(argv[1]));
write(2, "\n", 1);
}