1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-14 00:08:47 +02:00

🔨」 fix: if folder crash

This commit is contained in:
2024-07-14 15:39:28 +02:00
parent 4739d6b6f9
commit fe0285a5b2
17 changed files with 119 additions and 18 deletions

50
src/utils/free_list.c Normal file
View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/04 20:10:35 by adjoly #+# #+# */
/* Updated: 2024/07/10 01:19:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "parsing.h"
void free_redir(void *redir_v)
{
t_redirection *redir;
redir = redir_v;
free(redir->file_name);
free(redir);
}
void free_token(void *token_v)
{
t_token *token;
token = token_v;
free(token->argv);
ft_lstclear(&(token->redirection), free_redir);
free(token);
}
void free_cmd(void *content)
{
t_cmd *cmd;
cmd = (t_cmd *)content;
if (cmd->cmd)
free(cmd->cmd);
if (cmd->infile != STDIN_FILENO && cmd->infile != -1)
close(cmd->infile);
if (cmd->outfile != STDOUT_FILENO && cmd->outfile != -1)
close(cmd->outfile);
if (cmd->argv)
ft_free("a", &(cmd->argv));
if (cmd)
free(cmd);
}

23
src/utils/ft_arrlen.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arrlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/14 13:52:08 by adjoly #+# #+# */
/* Updated: 2024/07/14 14:25:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
size_t ft_arrlen(char **a)
{
char **tmp;
tmp = a;
while (*tmp)
tmp++;
return (tmp - a);
}

63
src/utils/get_to_free.c Normal file
View File

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_to_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 17:24:15 by adjoly #+# #+# */
/* Updated: 2024/07/14 13:59:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "env.h"
#include "libft.h"
t_env **get_env(t_env **env)
{
static t_env **ret;
if (env)
ret = env;
return (ret);
}
t_list **get_list(t_list **list)
{
static t_list **ret;
if (list)
ret = list;
return (ret);
}
t_list **get_list2(t_list **list)
{
static t_list **ret;
if (list)
ret = list;
return (ret);
}
int get_exit_code(int in)
{
static int exit_code;
if (in == 727)
exit_code = 727;
if (in != -1)
exit_code = in % 256;
if (exit_code < 0)
exit_code += 256;
return (exit_code);
}
int get_fd_heredoc(int in)
{
static int fd;
if (in != -1)
fd = in;
return (fd);
}

25
src/utils/is_str.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 10:23:40 by adjoly #+# #+# */
/* Updated: 2024/05/03 10:23:55 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdbool.h>
bool is_str(char *src, char *dst)
{
while (*src && *dst && *src == *dst)
{
src++;
dst++;
}
if (*dst)
return (false);
return (true);
}

23
src/utils/ret_cwd.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ret_cwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/25 10:41:43 by adjoly #+# #+# */
/* Updated: 2024/06/25 17:04:37 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtins.h"
#include "libft.h"
#include <unistd.h>
char *ret_cwd(void)
{
static char buf[PATH_MAX_LEN];
ft_bzero(buf, PATH_MAX_LEN);
return (getcwd(buf, PATH_MAX_LEN));
}