-
Notifications
You must be signed in to change notification settings - Fork 0
/
4auxiliar.c
57 lines (50 loc) · 1.67 KB
/
4auxiliar.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 4auxiliar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: guilmira <guilmira@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/19 11:04:00 by guilmira #+# #+# */
/* Updated: 2021/12/06 10:50:23 by guilmira ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
/** PURPOSE : Does the path of the command exist? Returns bool. */
int file_exists(char *str)
{
int fp;
fp = open(str, O_RDONLY);
if (fp == -1)
return (0);
close(fp);
return (1);
}
/** PURPOSE : Build an int array with every file descriptor of pipes. */
int *arg_descriptors(t_arguments *args)
{
int *ptr;
int number_of_fds;
number_of_fds = (args->total_commands - 1) * 2;
ptr = ft_calloc(number_of_fds, sizeof(int));
if (!ptr)
ft_shutdown(MEM, 0, args);
return (ptr);
}
/** PURPOSE : Returns content of position 'n' of list.
* Note: First element of the list is n = 0 */
void *ft_lst_position(t_list *lst, int n)
{
int i;
i = -1;
if (!lst)
return (NULL);
while (++i < n)
{
if (!lst->next)
return (NULL);
else
lst = lst->next;
}
return (lst->content);
}