-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_utils.c
executable file
·59 lines (51 loc) · 1.54 KB
/
error_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aivanyan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/29 14:30:41 by aivanyan #+# #+# */
/* Updated: 2023/03/03 21:22:19 by zkarapet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_putstr(char *str)
{
int len;
len = ft_strlen(str);
write(1, str, len);
}
int pipe_error(int pip)
{
if (pip < 0)
{
perror("pipe() returns -1\n");
return (1);
}
return (0);
}
void ft_print_error_and_exit(char *error, int code)
{
ft_putstr_fd(error, 2, 0);
g_status = code;
exit(code);
}
void dup_error(int du)
{
if (du < 0)
ft_print_error_and_exit("dup2 is < 0", 1);
}
void ft_print_error_with_arg(char *cmd, char *arg)
{
char *msg;
char *s1;
char *s2;
s1 = ft_strjoin_m(cmd, ": ");
s2 = ft_strjoin_m(arg, ": ");
msg = ft_strjoin3(s1, s2, "No such file or directory\n");
free(s1);
free(s2);
ft_putstr(msg);
free(msg);
}