aboutsummaryrefslogtreecommitdiff
path: root/src/create_files.c
blob: faee27ff4a975755f8c7f2b158202606812195ef (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   create_files.c                                     :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/01/16 16:23:51 by dkaiser           #+#    #+#             */
/*   Updated: 2025/01/16 19:16:33 by dkaiser          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"
#include <unistd.h>

void	create_files(t_list *files)
{
	t_redirection	*file;
	int				fd;

	while (files)
	{
        dbg("Test");
        if (files->content == NULL)
            continue;
		file = (t_redirection *)files->content;
        if (access(file->specifier, F_OK) != -1 && access(file->specifier, W_OK) == -1)
            break;
		if (file->type == OUTPUT_OVERRIDE)
		{
			fd = open(file->specifier, O_WRONLY | O_CREAT | O_TRUNC, 0644);
			close(fd);
		}
		else if (file->type == OUTPUT_APPEND)
		{
			fd = open(file->specifier, O_WRONLY | O_CREAT | O_APPEND, 0644);
			close(fd);
		}
        /* if (files->next == NULL) */
        /*     break; */
        /* if (((t_redirection *) files->next->content)->type == 0) */
        /*     break; */
		files = files->next;
	}
}