Minishell
 
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* file.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: ppontet <ppontet@student.42lyon.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/03/18 17:09:50 by ppontet #+# #+# */
9/* Updated: 2025/05/30 11:10:56 by ppontet ### ########lyon.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef FILE_H
14# define FILE_H
15
16# include "libft.h"
17# include "minishell.h"
18
19# define TMP_PATH "/tmp/"
20
21typedef struct s_tmp t_tmp;
22typedef struct s_file t_file;
23
28struct s_tmp
29{
30 char *name;
31 int fd;
32};
33
38struct s_file
39{
41 char *name;
43 t_bool parsed;
44 t_bool exist;
45 t_bool perm_read;
46 t_bool perm_write;
47 t_bool is_heredoc;
48 t_bool is_append;
49};
50
56int files_management(t_data *data);
57
59void *add_file(t_garbage *garbage, t_command *command,
60 t_token *token, t_file **command_file);
61int build_files_data(t_command *command);
63int build_file_access(t_file *file);
64char *ft_trim_word(char *str);
66t_tmp create_tmp(t_garbage *garbage, char *path, int nbr_try);
67char *read_heredoc(t_tmp *tmp, char *delimiteur);
68int verify_access(t_garbage *garbage, t_command *command);
70 t_file *already_searched);
71int fill_heredocs(t_garbage *garbage, t_command *command);
72int open_file_with_rights(t_garbage *garbage, t_file *file,
73 t_bool in_out);
74void read_write_to(t_garbage *garbage, t_command *command,
75 t_bool in_out);
76void fd_default(t_command *command);
78#endif
struct s_data t_data
Definition data_structure.h:38
struct s_command t_command
Definition data_structure.h:35
struct s_garbage t_garbage
Definition data_structure.h:26
struct s_tmp t_tmp
Definition data_structure.h:21
struct s_file t_file
Definition data_structure.h:22
struct s_token t_token
Definition data_structure.h:37
t_tmp create_tmp(t_garbage *garbage, char *path, int nbr_try)
Create a tmp file, verify if it already exist, tries to open it to verify permissions,...
Definition tmp_generator.c:33
t_file * search_last_file(t_file *file, t_file *already_searched)
Return the last file that is not already_searched.
Definition file_verify_access.c:33
t_command * remove_used_file_tokens(t_data *data)
Removes all the tokens of file redirections allready used.
Definition ft_file_tokens.c:27
char * ft_trim_word(char *str)
void * add_file(t_garbage *garbage, t_command *command, t_token *token, t_file **command_file)
Add a file to the stack given in param, each file added is at the beginning of the stack (reverse ord...
Definition file.c:94
int build_files_redirection(t_data *data)
Adds files to the file redirection structure.
Definition file_build.c:26
int fill_heredocs(t_garbage *garbage, t_command *command)
Fill all the heredocs in the correct order.
Definition heredoc.c:108
void fd_default(t_command *command)
Put the fds in command to there default values.
Definition file-general.c:120
int files_management(t_data *data)
Executes all the files redirection tests.
Definition file-general.c:28
char * read_heredoc(t_tmp *tmp, char *delimiteur)
Read from stdin and outputs to a file, stops reading when Ctrl+D or when a delimitor is found.
Definition heredoc.c:34
int build_files_data(t_command *command)
Build the data around the files in all commands.
Definition file_build.c:61
int build_file_access(t_file *file)
Build the file using access and check permissions.
Definition file.c:25
t_file * file_parser(t_file *file)
Parse the file structure.
Definition file.c:52
void read_write_to(t_garbage *garbage, t_command *command, t_bool in_out)
Opens the files to read and writes.
Definition file-general.c:92
int verify_access(t_garbage *garbage, t_command *command)
Verify that all files are valid if at least one file is invalid, modifies the boolean in command but ...
Definition file_verify_access.c:159
int open_file_with_rights(t_garbage *garbage, t_file *file, t_bool in_out)
Open a file with it's rights (permissions)
Definition file-general.c:61
Structure to handle all the data of a file.
Definition file.h:39
t_bool is_heredoc
Definition file.h:47
char * name
Definition file.h:41
t_file * next
Definition file.h:40
t_bool perm_read
Definition file.h:45
t_bool exist
Definition file.h:44
t_bool parsed
Definition file.h:43
t_bool is_append
Definition file.h:48
t_tmp * tmp
Definition file.h:42
t_bool perm_write
Definition file.h:46
Basic structure to help manipulating heredocs (tmp file)
Definition file.h:29
char * name
Definition file.h:30
int fd
Definition file.h:31