-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_print.c
70 lines (66 loc) · 1.68 KB
/
helpers_print.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
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)));
}
/**
* _printe - 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 _printe(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)
{
_printe(data->program_name);
_printe(": ");
_printe(n_as_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(": ");
_printe(n_as_string);
_printe(": ");
_printe(data->command_name);
_printe(": not found\n");
}
else if (errorcode == 126)
{
_printe(data->program_name);
_printe(": ");
_printe(n_as_string);
_printe(": ");
_printe(data->command_name);
_printe(": Permission denied\n");
}
return (0);
}