-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexit_error.c
68 lines (62 loc) · 1.96 KB
/
exit_error.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aelsayed <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/14 20:57:25 by aelsayed #+# #+# */
/* Updated: 2025/02/13 19:07:25 by aelsayed ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
void exit_error(int specifier, int exitt, char error, char *file)
{
if (specifier == -1)
{
unlink(".here_doc_tmp");
if (error == 'c')
printfd(2, "pipex: command not found: %s\n", file);
else if (error == 'o' && file)
printfd(2, "pipex: %s: %s\n", strerror(errno), file);
else if (error == 'e' || error == 'd')
printfd(2, "pipex: %s\n", strerror(errno));
if (exitt == 2)
exit(globale_variable(0b01111111));
if (exitt)
exit(errno);
}
}
int bpath_err(char **av, int ac)
{
int i;
i = 3;
while (i < ac - 1)
exit_error(-1, 0, 'c', av[i++]);
unlink(".here_doc_tmp");
return (1);
}
int file_opener(char *infile, char *outfile, char c, int perm)
{
int fdi;
int fdo;
if (perm)
return (open(outfile, O_RDWR | O_CREAT | O_APPEND, 0644));
fdo = open(outfile, O_RDWR | O_CREAT | O_TRUNC, 0644);
fdi = open(infile, O_RDONLY);
if (fdi == -1 && fdo == -1)
{
exit_error(fdi, 0, 'o', infile);
exit_error(fdo, 0, 'o', outfile);
exit(1);
}
if (fdo == -1)
{
exit_error(fdo, 0, 'o', outfile);
exit(1);
}
if (c == 'i')
return (fdi);
else
return (fdo);
}