-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_p.c
67 lines (59 loc) · 1.5 KB
/
helper_p.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
62
63
64
65
66
67
#include "shell.h"
/**
* _print - function writes a array of chars in the standar output
* @string: pointer to the input array of chars
* Return: Returns the number of bytes writed or -1
*/
int _print(char *string)
{
return (write(STDOUT_FILENO, string, _str_length(string)));
}
/**
* _printe - function writes a array of chars in the standar output
* @string: pointer to the input array of chars
* Return: Returns the number of bytes writed or -1
*/
int _printe(char *string)
{
return (write(STDERR_FILENO, string, _str_length(string)));
}
/**
* _print_error - function writes a array of chars in the standart error
* @data: a pointer to the program's data'
* @errorcode: error code to print
* Return: Returns the number of bytes writed or -1
*/
int _print_error(int errorcode, data_of_program *data)
{
char num_string[10] = {'\0'};
_long_to_string((long) data->exec_counter, num_string, 10);
if (errorcode == 2 || errorcode == 3)
{
_printe(data->program_name);
_printe(": ");
_printe(num_string);
_printe(": ");
_printe(data->tokens[0]);
if (errorcode == 2)
_printe(": Illegal number: ");
else
_printe(": can't cd to ");
_printe(data->tokens[1]);
_printe("\n");
}
else if (errorcode == 127)
{
_printe(data->program_name);
_printe(": No such file or directory\n");
}
else if (errorcode == 126)
{
_printe(data->program_name);
_printe(": ");
_printe(num_string);
_printe(": ");
_printe(data->command_name);
_printe(": Permission denied\n");
}
return (0);
}