-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_error.c
More file actions
40 lines (36 loc) · 741 Bytes
/
get_error.c
File metadata and controls
40 lines (36 loc) · 741 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
#include "holberton.h"
/**
* get_error - calls the error according the builtin, syntax or permission
* @datash: data structure that contains arguments
* @eval: error value
* Return: error
*/
int get_error(data_shell *datash, int eval)
{
char *error;
switch (eval)
{
case -1:
error = error_env(datash);
break;
case 126:
error = error_path_126(datash);
break;
case 127:
error = error_not_found(datash);
break;
case 2:
if (_strcmp("exit", datash->args[0]) == 0)
error = error_exit_shell(datash);
else if (_strcmp("cd", datash->args[0]) == 0)
error = error_get_cd(datash);
break;
}
if (error)
{
write(STDERR_FILENO, error, _strlen(error));
free(error);
}
datash->status = eval;
return (eval);
}