Repository navigation
Expand file tree
/
Copy pathutils_file.c
More file actions
45 lines (41 loc) · 1.68 KB
/
Copy pathutils_file.c
File metadata and controls
45 lines (41 loc) · 1.68 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bde-koni <bde-koni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/12 14:21:04 by bde-koni #+# #+# */
/* Updated: 2025/05/12 17:25:51 by bde-koni ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
#include <fcntl.h>
#include <stdio.h>
int ft_open(char *file, int oflag)
{
int fd;
if (oflag == READ)
fd = open(file, O_RDONLY); //read fd that is first parameter
else
fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644); // write in fd that is last parameter
if (fd < 0 && oflag == READ)
exit_with_failure("Opening fd1 failed\n", 1, 1);
else if (fd < 0)
exit_with_failure("Opening fd2 failed\n", 1, 1);
return (fd);
}
void ft_close(int fd, int flag)
{
if (close(fd) == -1)
{
if (flag == 1)
exit_with_failure("Closing fd1 failed\n", 1, 1);
else if (flag == 2)
exit_with_failure("Closing fd2 failed\n", 1, 1);
else if (flag == 3)
exit_with_failure("Closing pipe[READ] failed\n", 1, 1);
else if (flag == 3)
exit_with_failure("Closing pipe[WRITE] failed\n", 1, 1);
}
}