Minishell
 
Loading...
Searching...
No Matches
Files functions

Function to manipulate files. More...

Functions

int files_management (t_data *data)
 Executes all the files redirection tests.
 
int build_files_redirection (t_data *data)
 Adds files to the file redirection structure.
 
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 order)
 
int build_files_data (t_command *command)
 Build the data around the files in all commands.
 
t_commandremove_used_file_tokens (t_data *data)
 Removes all the tokens of file redirections allready used.
 
int build_file_access (t_file *file)
 Build the file using access and check permissions.
 
char * ft_trim_word (char *str)
 
t_filefile_parser (t_file *file)
 Parse the file structure.
 
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, and returns the result.
 
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.
 
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 still return 0.
 
t_filesearch_last_file (t_file *file, t_file *already_searched)
 Return the last file that is not already_searched.
 
int fill_heredocs (t_garbage *garbage, t_command *command)
 Fill all the heredocs in the correct order.
 
int open_file_with_rights (t_garbage *garbage, t_file *file, t_bool in_out)
 Open a file with it's rights (permissions)
 
void read_write_to (t_garbage *garbage, t_command *command, t_bool in_out)
 Opens the files to read and writes.
 
void fd_default (t_command *command)
 Put the fds in command to there default values.
 

Detailed Description

Function to manipulate files.

Function Documentation

◆ add_file()

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 order)

Parameters
garbagegarbage structure
commandcommand structure
tokentoken containing str informations
command_filestack to assign a file
Returns
void* NULL if error, command if no stack given, and file if all's good
Here is the call graph for this function:

◆ build_file_access()

int build_file_access ( t_file * file)

Build the file using access and check permissions.

Parameters
filefile structure
Returns
int 0, OK, -1 error

◆ build_files_data()

int build_files_data ( t_command * command)

Build the data around the files in all commands.

Parameters
commandfile structure
Returns
int 0 OK, 1 error

◆ build_files_redirection()

int build_files_redirection ( t_data * data)

Adds files to the file redirection structure.

Parameters
datadata structure
Returns
int 0, OK, -1 error
Here is the call graph for this function:

◆ create_tmp()

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, and returns the result.

Parameters
garbagegarbage structure
pathpath where to create the file
nbr_trynumber of try to create a tmp file
Returns
t_tmp structure with the path+name of created name
Here is the call graph for this function:

◆ fd_default()

void fd_default ( t_command * command)

Put the fds in command to there default values.

Parameters
commandcommand structure

◆ file_parser()

t_file * file_parser ( t_file * file)

Parse the file structure.

Parameters
filefile structure
Returns
t_file* file given in paramter
Here is the call graph for this function:

◆ files_management()

int files_management ( t_data * data)

Executes all the files redirection tests.

Parameters
datadata structure
Returns
int 0 OK, 1 is at least one file redirection is invalid
Here is the call graph for this function:

◆ fill_heredocs()

int fill_heredocs ( t_garbage * garbage,
t_command * command )

Fill all the heredocs in the correct order.

Parameters
garbagegarbage structure
commandcommand structure
Returns
int 0 OK, otherwise error
Here is the call graph for this function:

◆ ft_trim_word()

char * ft_trim_word ( char * str)

◆ open_file_with_rights()

int open_file_with_rights ( t_garbage * garbage,
t_file * file,
t_bool in_out )

Open a file with it's rights (permissions)

Parameters
garbagegarbage structure
filefile structure
in_out0 = IN, 1 = OUT
Returns
int
Here is the call graph for this function:

◆ read_heredoc()

char * read_heredoc ( t_tmp * tmp,
char * delimitor )

Read from stdin and outputs to a file, stops reading when Ctrl+D or when a delimitor is found.

Parameters
tmpstructure for heredocs
delimitorstring to know when to stop reading
Returns
char* tmp->name if successful, NULL otherwise
Here is the call graph for this function:

◆ read_write_to()

void read_write_to ( t_garbage * garbage,
t_command * command,
t_bool in_out )

Opens the files to read and writes.

Parameters
garbagegarbage structure
commandcommand structure
in_out0 = IN, 1 = OUT
Here is the call graph for this function:

◆ remove_used_file_tokens()

t_command * remove_used_file_tokens ( t_data * data)

Removes all the tokens of file redirections allready used.

Parameters
datadata structure
Returns
t_command*

◆ search_last_file()

t_file * search_last_file ( t_file * file,
t_file * already_searched )

Return the last file that is not already_searched.

Parameters
filefile structure
already_searchedprevious file from search
Returns
t_file* last file begore already_searched

◆ verify_access()

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 still return 0.

Parameters
garbagegarbage structure
commandcommand structure
Returns
int 0 OK, error otherwise