-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_p.c
More file actions
70 lines (66 loc) · 1.72 KB
/
helper_p.c
File metadata and controls
70 lines (66 loc) · 1.72 KB
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
68
69
70
#include "shell.h"
/**
* _print - writes a array of chars in the standar output
* @string: pointer to the array of chars
* Return: the number of bytes writed or .
* On error, -1 is returned, and errno is set appropriately.
*/
int _print(char *string)
{
return (write(STDOUT_FILENO, string, str_length(string)));
}
/**
* print_arr - writes a array of chars in the standar error
* @string: pointer to the array of chars
* Return: the number of bytes writed or .
* On error, -1 is returned, and errno is set appropriately.
*/
int print_arr(char *string)
{
return (write(STDERR_FILENO, string, str_length(string)));
}
/**
* _print_error - writes a array of chars in the standart error
* @data: a pointer to the program's data'
* @errorcode: error code to print
* Return: the number of bytes writed or .
* On error, -1 is returned, and errno is set appropriately.
*/
int _print_error(int errorcode, data_of_program *data)
{
char n_as_string[10] = {'\0'};
long_to_string((long) data->exec_counter, n_as_string, 10);
if (errorcode == 2 || errorcode == 3)
{
print_arr(data->program_name);
print_arr(": ");
print_arr(n_as_string);
print_arr(": ");
print_arr(data->tokens[0]);
if (errorcode == 2)
print_arr(": Illegal number: ");
else
print_arr(": can't cd to ");
print_arr(data->tokens[1]);
print_arr("\n");
}
else if (errorcode == 127)
{
print_arr(data->program_name);
print_arr(": ");
print_arr(n_as_string);
print_arr(": ");
print_arr(data->command_name);
print_arr(": not found\n");
}
else if (errorcode == 126)
{
print_arr(data->program_name);
print_arr(": ");
print_arr(n_as_string);
print_arr(": ");
print_arr(data->command_name);
print_arr(": Permission denied\n");
}
return (0);
}