-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal_error.c
More file actions
49 lines (44 loc) · 832 Bytes
/
global_error.c
File metadata and controls
49 lines (44 loc) · 832 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
41
42
43
44
45
46
47
48
49
#include "minishell.h"
int export_key_error(int *flag)
{
*flag = 1;
printf("minishell: export: not a valid identifier\n");
return (1);
}
int builtin_error(char *builtin, char *to_free1, char *to_free2)
{
if (to_free1)
free(to_free1);
if (to_free2)
free(to_free2);
printf("minishell: %s: %s\n", builtin, strerror(errno));
return (1);
}
void clean(t_data *d)
{
int i;
i = -1;
while (++i < d->amount_of_alloc_lines)
free(d->env[i]);
if (d->env)
free(d->env);
}
int global_error(t_data *d)
{
if (d->backup.fd_out != -1)
{
if (dup2(d->backup.fd_out, 1) < 0)
exit(1);
if (close(d->backup.fd_out) < 0)
exit(1);
}
if (d->backup.fd_in != -1)
{
if (dup2(d->backup.fd_in, 0) < 0)
exit(1);
if (close(d->backup.fd_in) < 0)
exit(1);
}
printf("minishell: %s\n", strerror(errno));
return (1);
}