-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrorhandlers.c
60 lines (55 loc) · 1.79 KB
/
errorhandlers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errorhandlers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dcelsa <dcelsa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 16:02:23 by dcelsa #+# #+# */
/* Updated: 2022/04/03 21:17:22 by dcelsa ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int cmdnotfound(char *prog, char *place)
{
ft_putstr_fd(prog, 2);
ft_putstr_fd(": ", 2);
ft_putstr_fd(place, 2);
ft_putstr_fd(": command not found\n", 2);
exit(127);
}
void redirerr(char *prog, char *place)
{
ft_putstr_fd(prog, 2);
ft_putstr_fd(": ", 2);
ft_putstr_fd(place, 2);
ft_putstr_fd(": ambiguous redirect\n", 2);
exit(1);
}
void parserr(char *prog, char *place)
{
ft_putstr_fd(prog, 2);
if (!istoken(place, STPSYMBS))
ft_putstr_fd(": parse error near '", 2);
else
ft_putstr_fd(": unexpected token '", 2);
if (*place == '\0')
ft_putstr_fd("\\n", 2);
else
ft_putchar_fd(*place, 2);
ft_putendl_fd("'", 2);
exit(1);
}
int error_handler(char *prog, char *place, int funcres)
{
if (funcres >= 0)
return (funcres);
ft_putstr_fd(prog, 2);
ft_putstr_fd(": ", 2);
if (place)
ft_putstr_fd(place, 2);
if (place)
ft_putstr_fd(": ", 2);
ft_putendl_fd(strerror(errno), 2);
exit(1);
}