Updated Filelist
This commit is contained in:
parent
ed4015a8fe
commit
f05826942a
15 changed files with 182 additions and 163 deletions
|
|
@ -6,44 +6,57 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/29 17:24:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/29 19:09:56 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/30 14:30:45 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef _REDIRECTION_H
|
||||
#define _REDIRECTION_H
|
||||
# define _REDIRECTION_H
|
||||
|
||||
#include "me/types.h"
|
||||
# include "me/types.h"
|
||||
# include "me/fs/fs.h"
|
||||
|
||||
typedef struct s_exec_redirect t_exec_redirect;
|
||||
typedef struct s_exec_redirect_fd t_exec_redirect_fd;
|
||||
typedef struct s_exec_redirect_heredoc t_exec_redirect_heredoc;
|
||||
typedef union u_exec_redirect t_exec_redirect;
|
||||
|
||||
struct s_exec_redirect_heredoc
|
||||
{
|
||||
};
|
||||
|
||||
struct s_exec_redirect_fd
|
||||
{
|
||||
int infile_fd;
|
||||
int outfile_fd;
|
||||
t_str file_path;
|
||||
};
|
||||
|
||||
union u_exec_redirect_data {
|
||||
t_exec_redirect_heredoc heredoc;
|
||||
t_exec_redirect_fd fd;
|
||||
};
|
||||
enum e_exec_redirect_kind
|
||||
{
|
||||
EXEC_REDIR_FD,
|
||||
EXEC_REDIR_HEREDOC,
|
||||
EXEC_REDIR_PIPE,
|
||||
};
|
||||
|
||||
struct s_exec_redirect
|
||||
union u_exec_redirect
|
||||
{
|
||||
union u_exec_redirect_data data;
|
||||
enum e_exec_redirect_kind kind;
|
||||
enum e_exec_redirect_kind kind;
|
||||
struct s_exec_redirect_heredoc
|
||||
{
|
||||
enum e_exec_redirect_kind kind;
|
||||
int in_fd;
|
||||
t_const_str data;
|
||||
} heredoc;
|
||||
struct s_exec_redirect_fd
|
||||
{
|
||||
enum e_exec_redirect_kind kind;
|
||||
int lhs_fd;
|
||||
int rhs_fd;
|
||||
t_const_str file_path;
|
||||
} fd;
|
||||
struct s_exec_redirect_pipe
|
||||
{
|
||||
enum e_exec_redirect_kind kind;
|
||||
int stdin;
|
||||
int stdout;
|
||||
} piped;
|
||||
};
|
||||
|
||||
static inline void free_redirection(t_exec_redirect self)
|
||||
{
|
||||
void mem_free(void *ptr);
|
||||
|
||||
if (self.kind == EXEC_REDIR_FD)
|
||||
(void)(self.fd.file_path != NULL && (mem_free(self.fd.file_path), 1));
|
||||
if (self.kind == EXEC_REDIR_HEREDOC)
|
||||
(void)(self.heredoc.data != NULL && (mem_free(self.heredoc.data), 1));
|
||||
}
|
||||
|
||||
#endif /* _REDIRECTION_H */
|
||||
|
|
|
|||
|
|
@ -6,25 +6,26 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/04 17:57:29 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/04 17:59:30 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/30 14:33:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PIPE_H
|
||||
# define PIPE_H
|
||||
#define PIPE_H
|
||||
|
||||
# include "me/types.h"
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief Pipe structure
|
||||
typedef struct s_pipe
|
||||
typedef struct s_exec_pipe
|
||||
{
|
||||
int read;
|
||||
int write;
|
||||
} t_pipe;
|
||||
t_fd *read;
|
||||
t_fd *write;
|
||||
} t_exec_pipe;
|
||||
|
||||
/// @brief Create a pipe
|
||||
/// @param[out] out the created pipe
|
||||
/// @return the error
|
||||
t_error create_pipe(t_pipe *out);
|
||||
t_error create_pipe(t_exec_pipe *out);
|
||||
|
||||
#endif /* PIPE_H */
|
||||
|
|
|
|||
|
|
@ -6,37 +6,36 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/03 15:43:08 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/11 18:59:04 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/30 13:23:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PROCESS_H
|
||||
# define PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_str.h"
|
||||
# include "me/vec/vec_u8.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
|
||||
typedef t_i32 t_pid;
|
||||
typedef t_i32 t_exit_code;
|
||||
typedef t_i32 t_pid;
|
||||
typedef t_i32 t_exit_code;
|
||||
|
||||
enum e_redirection
|
||||
enum e_redirection
|
||||
{
|
||||
R_INHERITED = 0,
|
||||
R_PIPED = 1,
|
||||
R_FD = 2,
|
||||
};
|
||||
|
||||
union u_redirection
|
||||
{
|
||||
struct s_fd_redirection
|
||||
union u_redirection {
|
||||
struct s_fd_redirection
|
||||
{
|
||||
int value;
|
||||
int value;
|
||||
} fd;
|
||||
struct s_piped_redirection
|
||||
struct s_piped_redirection
|
||||
{
|
||||
} piped;
|
||||
struct s_inherited_redirection
|
||||
struct s_inherited_redirection
|
||||
{
|
||||
} inherited;
|
||||
};
|
||||
|
|
@ -44,14 +43,14 @@ union u_redirection
|
|||
/// @brief Redirection for spawning a process
|
||||
typedef struct s_redirection
|
||||
{
|
||||
enum e_redirection tag;
|
||||
union u_redirection vals;
|
||||
} t_redirection;
|
||||
enum e_redirection tag;
|
||||
union u_redirection vals;
|
||||
} t_redirection;
|
||||
|
||||
/// @brief Create a piped redirection
|
||||
/// @param void
|
||||
/// @return the redirection
|
||||
static inline t_redirection piped(void)
|
||||
static inline t_redirection piped(void)
|
||||
{
|
||||
return ((t_redirection){
|
||||
.tag = R_PIPED,
|
||||
|
|
@ -61,7 +60,7 @@ static inline t_redirection piped(void)
|
|||
/// @brief Create an inherited redirection (inherit from the parent process)
|
||||
/// @param void
|
||||
/// @return the redirection
|
||||
static inline t_redirection inherited(void)
|
||||
static inline t_redirection inherited(void)
|
||||
{
|
||||
return ((t_redirection){
|
||||
.tag = R_INHERITED,
|
||||
|
|
@ -71,16 +70,16 @@ static inline t_redirection inherited(void)
|
|||
/// @brief Create a file descriptor redirection
|
||||
/// @param fd file descriptor to redirect
|
||||
/// @return the redirection
|
||||
static inline t_redirection fd(int fd)
|
||||
static inline t_redirection fd(int fd)
|
||||
{
|
||||
return ((t_redirection){.tag = R_FD, \
|
||||
.vals = (union u_redirection){\
|
||||
.fd = {.value = fd}, \
|
||||
return ((t_redirection){.tag = R_FD,
|
||||
.vals = (union u_redirection){
|
||||
.fd = {.value = fd},
|
||||
}});
|
||||
}
|
||||
|
||||
/// @brief Wrapped file descriptor tag
|
||||
enum e_wrapped_fd_tag
|
||||
enum e_wrapped_fd_tag
|
||||
{
|
||||
READ_ONLY,
|
||||
WRITE_ONLY,
|
||||
|
|
@ -89,85 +88,82 @@ enum e_wrapped_fd_tag
|
|||
};
|
||||
|
||||
/// @brief Wrapped file descriptor
|
||||
union u_wrapped_fd
|
||||
{
|
||||
struct s_read_only
|
||||
union u_wrapped_fd {
|
||||
struct s_read_only
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
} ro;
|
||||
struct s_write_only
|
||||
struct s_write_only
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
} wo;
|
||||
struct s_read_write
|
||||
struct s_read_write
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
} rw;
|
||||
};
|
||||
|
||||
/// @brief Wrapped file descriptor
|
||||
typedef struct s_wrapped_fd
|
||||
{
|
||||
enum e_wrapped_fd_tag tag;
|
||||
union u_wrapped_fd vals;
|
||||
} t_wrapped_fd;
|
||||
enum e_wrapped_fd_tag tag;
|
||||
union u_wrapped_fd vals;
|
||||
} t_wrapped_fd;
|
||||
|
||||
/// @brief Create a Read only wrapped file descriptor
|
||||
/// @param fd file descriptor to wrap
|
||||
/// @return the wrapped file descriptor
|
||||
static inline t_wrapped_fd ro(int fd)
|
||||
static inline t_wrapped_fd ro(int fd)
|
||||
{
|
||||
return ((t_wrapped_fd){.tag = READ_ONLY, \
|
||||
.vals = (union u_wrapped_fd){\
|
||||
.ro = {.fd = fd}, \
|
||||
}});
|
||||
return ((t_wrapped_fd){.tag = READ_ONLY,
|
||||
.vals = (union u_wrapped_fd){
|
||||
.ro = {.fd = fd},
|
||||
}});
|
||||
}
|
||||
|
||||
/// @brief Create a Write only wrapped file descriptor
|
||||
/// @param fd file descriptor to wrap
|
||||
/// @return the wrapped file descriptor
|
||||
static inline t_wrapped_fd wo(int fd)
|
||||
static inline t_wrapped_fd wo(int fd)
|
||||
{
|
||||
return ((t_wrapped_fd){.tag = WRITE_ONLY,
|
||||
.vals = (union u_wrapped_fd){.wo = {.fd = fd}}});
|
||||
return ((t_wrapped_fd){.tag = WRITE_ONLY, .vals = (union u_wrapped_fd){.wo = {.fd = fd}}});
|
||||
}
|
||||
|
||||
/// @brief Spawn information
|
||||
typedef struct s_spawn_info
|
||||
{
|
||||
t_redirection stdin;
|
||||
t_redirection stdout;
|
||||
t_redirection stderr;
|
||||
t_vec_str arguments;
|
||||
t_vec_str environement;
|
||||
t_str binary_path;
|
||||
void (*forked_free)(void *);
|
||||
void *forked_free_args;
|
||||
} t_spawn_info;
|
||||
t_redirection stdin;
|
||||
t_redirection stdout;
|
||||
t_redirection stderr;
|
||||
t_vec_str arguments;
|
||||
t_vec_str environement;
|
||||
t_str binary_path;
|
||||
void (*forked_free)(void *);
|
||||
void *forked_free_args;
|
||||
} t_spawn_info;
|
||||
|
||||
/// @brief Process information
|
||||
typedef struct s_process
|
||||
{
|
||||
t_wrapped_fd stdin;
|
||||
t_wrapped_fd stdout;
|
||||
t_wrapped_fd stderr;
|
||||
t_pid pid;
|
||||
} t_process;
|
||||
t_wrapped_fd stdin;
|
||||
t_wrapped_fd stdout;
|
||||
t_wrapped_fd stderr;
|
||||
t_pid pid;
|
||||
} t_process;
|
||||
/// @struct Process output
|
||||
/// @brief Process output information
|
||||
typedef struct s_process_output
|
||||
{
|
||||
t_pid pid;
|
||||
t_vec_u8 stdout;
|
||||
t_vec_u8 stderr;
|
||||
t_exit_code exit_code;
|
||||
} t_process_output;
|
||||
t_pid pid;
|
||||
t_vec_u8 stdout;
|
||||
t_vec_u8 stderr;
|
||||
t_exit_code exit_code;
|
||||
} t_process_output;
|
||||
|
||||
/// @brief Spawn a new process with the given information
|
||||
/// @param info the information to spawn the process
|
||||
/// @param process data returned by the function
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error spawn_process(t_spawn_info info,
|
||||
t_process *process);
|
||||
t_error spawn_process(t_spawn_info info, t_process *process);
|
||||
|
||||
#endif /* PROCESS_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue