Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
9a44444070 | ||
|
cd72d29c63 | ||
|
de2a6e77d7 | ||
|
64bd25ae09 | ||
|
ce15b661f3 | ||
|
25c4b28f4c | ||
|
4a534c8156 | ||
|
fdd37da7d0 | ||
|
f094553b79 | ||
|
79e2ca6f1b | ||
|
40718a99ac | ||
|
4f7e1a56ef | ||
|
8a421600f4 | ||
|
2362474fd6 | ||
|
4123c5dca3 | ||
|
e89ccb64b2 | ||
|
e6304a9f40 | ||
|
aa5f198c46 | ||
|
e32efb9312 | ||
|
cfd4a67957 | ||
|
85af14cd9f | ||
|
d22bc173f1 | ||
|
58459bc0c1 | ||
|
aa8e971688 | ||
|
05d8424f75 | ||
|
cf62dae53b | ||
|
852248636f |
4
.ccls
Normal file
4
.ccls
Normal file
@@ -0,0 +1,4 @@
|
||||
clang
|
||||
-Iincludes
|
||||
-Ilibft/includes
|
||||
%c %h -Wall -Wextra -Werror -g-Wall -Wextra -Werror -g
|
8
Makefile
8
Makefile
@@ -6,7 +6,7 @@
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
|
||||
# Updated: 2020/02/14 11:56:31 by tmaze ### ########.fr #
|
||||
# Updated: 2020/01/30 12:00:42 by tmaze ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
@@ -41,14 +41,10 @@ SRC = main.c \
|
||||
cmd_setenv.c \
|
||||
cmd_unsetenv.c \
|
||||
cmd_cd.c \
|
||||
cmd_cd_utils.c \
|
||||
cmd_echo.c \
|
||||
ms_exec.c \
|
||||
ms_ext.c \
|
||||
put_error_cd.c \
|
||||
ms_exec_utils.c \
|
||||
def_env.c \
|
||||
check_path_slash_cd.c
|
||||
put_error_cd.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
|
33
README.org
Normal file
33
README.org
Normal file
@@ -0,0 +1,33 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# README.org :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2018/10/26 13:33:24 by tmaze #+# #+# #
|
||||
# Updated: 2018/11/18 16:57:11 by tmaze ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
#+AUTHOR: tmaze
|
||||
#+TITLE: 42Minishell
|
||||
|
||||
/Minishell project from Ecole 42/
|
||||
|
||||
* Todo list
|
||||
** TODO étudier les différents man du sujet [5/10]
|
||||
- [X] access
|
||||
- [X] open, close, read, write
|
||||
- [X] getcwd, chdir
|
||||
- [X] stat, lstat, fstat
|
||||
- [X] fork, execve
|
||||
- [ ] wait, waitpid, wait3, wait4
|
||||
- [ ] signal, kill
|
||||
- [ ] exit
|
||||
- [ ] environ
|
||||
- [ ] builtin
|
||||
** TODO réaliser un shell qui accepte les commandes
|
||||
- [ ] lanceur de binaires
|
||||
- [ ] gestion de l'environement
|
||||
** TODO réaliser les builtins
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/01 15:57:09 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/26 22:19:25 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -39,17 +39,4 @@ void *ft_strdel_null(char **s);
|
||||
void *put_error_cd(char *file, char *msg);
|
||||
int put_error_cd2(char *file, char *msg);
|
||||
|
||||
char *check_path_slash_cd(char *exec);
|
||||
|
||||
void exec_cmd_child(char *path, char **argv, char **env_tab,
|
||||
t_env **env);
|
||||
int ft_isin(char *str, char c);
|
||||
void *put_error(char *file, char *msg);
|
||||
|
||||
t_env *def_env(void);
|
||||
|
||||
void *return_null(char *msg);
|
||||
|
||||
t_env *cd_updateenv(char *key, char *val, t_env **env);
|
||||
|
||||
#endif
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/14 12:28:38 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/12/06 09:57:17 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -374,7 +374,6 @@ int ft_putendl_fd2(char const *s, int fd);
|
||||
void ft_envdelelem(t_env **elem);
|
||||
void ft_envdel(t_env **env);
|
||||
t_env *ft_envnew(char *env);
|
||||
t_env *ft_envnewinit(char *key, char *val);
|
||||
t_env *ft_envaddend(t_env **alst, t_env *new);
|
||||
t_env *ft_envgetelem(char *key, t_env *env);
|
||||
char *ft_envtochar(t_env *env);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/12/05 14:54:55 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/14 12:28:20 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/12/05 17:12:59 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -27,18 +27,3 @@ t_env *ft_envnew(char *env)
|
||||
ft_envdelelem(&ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
t_env *ft_envnewinit(char *key, char *val)
|
||||
{
|
||||
t_env *ret;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
if ((ret = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
|
||||
if ((ret->key = ft_strdup(key)) != NULL)
|
||||
if ((ret->val = ft_strdup(val)) != NULL)
|
||||
return (ret);
|
||||
ft_envdelelem(&ret);
|
||||
return (ret);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/12/05 19:10:38 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/07 15:26:10 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/12/05 19:10:52 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@@ -1,36 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_path_slach_cd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/02/01 15:29:57 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/01 15:31:19 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
char *check_path_slash_cd(char *exec)
|
||||
{
|
||||
int i;
|
||||
struct stat info;
|
||||
struct stat info2;
|
||||
|
||||
if (exec[0] == '/')
|
||||
{
|
||||
if ((i = access(exec, F_OK)) != 0)
|
||||
return (put_error_cd(exec, "no such file or directory"));
|
||||
if ((i = lstat(exec, &info)) != 0)
|
||||
return (put_error_cd(exec, "can't determine info"));
|
||||
if ((S_ISLNK(info.st_mode)
|
||||
&& ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode)))
|
||||
&& !S_ISDIR(info.st_mode))
|
||||
return (put_error_cd(exec, "not a directory"));
|
||||
if ((i = access(exec, X_OK)) != 0)
|
||||
return (put_error_cd(exec, "permission denied"));
|
||||
return (exec);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
@@ -6,12 +6,35 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/01 15:32:59 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/26 22:17:48 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
char *check_path_slash_cd(char *exec)
|
||||
{
|
||||
int i;
|
||||
struct stat info;
|
||||
struct stat info2;
|
||||
|
||||
if (exec[0] == '/')
|
||||
{
|
||||
if ((i = access(exec, F_OK)) != 0)
|
||||
return (put_error_cd(exec, "no such file or directory"));
|
||||
if ((i = lstat(exec, &info)) != 0)
|
||||
return (put_error_cd(exec, "can't determine info"));
|
||||
if ((S_ISLNK(info.st_mode)
|
||||
&& ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode)))
|
||||
&& !S_ISDIR(info.st_mode))
|
||||
return (put_error_cd(exec, "not a directory"));
|
||||
if ((i = access(exec, X_OK)) != 0)
|
||||
return (put_error_cd(exec, "permission denied"));
|
||||
return (exec);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int cmd_cd_update_env(char *path, t_env **env, char opt)
|
||||
{
|
||||
t_env *pwd;
|
||||
@@ -25,8 +48,8 @@ int cmd_cd_update_env(char *path, t_env **env, char opt)
|
||||
if (getcwd(p_path, 4096) == NULL || (oldpwd = ft_strdup(pwd->val)) == NULL
|
||||
|| ft_realpath(path, &c_path) == NULL)
|
||||
return (put_error_cd2(path, "error"));
|
||||
if (cd_updateenv("PWD", ((opt == 'P') ? p_path : c_path), env) == NULL
|
||||
|| cd_updateenv("OLDPWD", oldpwd, env) == NULL)
|
||||
if (ft_envupdate("PWD", *env, ((opt == 'P') ? p_path : c_path)) == NULL
|
||||
|| ft_envupdate("OLDPWD", *env, oldpwd) == NULL)
|
||||
{
|
||||
ft_strdel(&oldpwd);
|
||||
ft_strdel(&c_path);
|
||||
|
@@ -1,31 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cmd_cd_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/02/14 11:55:54 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/14 11:56:53 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_env *cd_updateenv(char *key, char *val, t_env **env)
|
||||
{
|
||||
t_env *tmp;
|
||||
|
||||
if ((tmp = ft_envgetelem(key, *env)) != NULL)
|
||||
ft_envupdate(key, *env, val);
|
||||
else if ((tmp = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
|
||||
{
|
||||
if ((tmp->key = ft_strdup(key)) == NULL)
|
||||
ft_envdelelem(&tmp);
|
||||
if (tmp && (tmp->val = ft_strdup(val)) == NULL)
|
||||
ft_envdelelem(&tmp);
|
||||
if (tmp)
|
||||
ft_envaddend(env, tmp);
|
||||
}
|
||||
return (tmp);
|
||||
}
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/20 14:41:08 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/07 15:56:06 by tmaze ### ########.fr */
|
||||
/* Updated: 2019/11/10 21:38:30 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -21,11 +21,14 @@ int cmd_setenv(char **argv, t_env **env)
|
||||
{
|
||||
if (argv[1] && (tmp = ft_envgetelem(new->key, *env)) != NULL)
|
||||
{
|
||||
ft_envupdate(new->key, *env, new->val);
|
||||
ft_envdelelem(&new);
|
||||
ft_strdel(&(tmp->val));
|
||||
tmp->val = new->val;
|
||||
ft_strdel(&(new->key));
|
||||
ft_memdel((void**)&new);
|
||||
}
|
||||
else
|
||||
ft_envaddend(env, new);
|
||||
ft_envclean(env);
|
||||
return (0);
|
||||
}
|
||||
else if (argv[1] && argv[1][0] != '=' && !ft_strchr(argv[1], '='))
|
||||
|
@@ -1,40 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* def_env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/02/01 15:53:22 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/01 15:53:34 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_env *def_env(void)
|
||||
{
|
||||
t_env *ret;
|
||||
t_env *n;
|
||||
char p[PATH_MAX];
|
||||
|
||||
n = ft_memalloc(sizeof(t_env));
|
||||
if (n != NULL && ((n->key = ft_strnew(3)) == NULL || !getcwd(p, PATH_MAX)))
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_strcpy(n->key, "PWD");
|
||||
if (n != NULL && (n->val = ft_strdup(p)) == NULL)
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_envaddend(&ret, n);
|
||||
n = ft_memalloc(sizeof(t_env));
|
||||
if (n != NULL && (n->key = ft_strnew(5)) == NULL)
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_strcpy(n->key, "SHLVL");
|
||||
if (n != NULL && (n->val = ft_strdup("1")) == NULL)
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_envaddend(&ret, n);
|
||||
return (ret);
|
||||
}
|
38
srcs/main.c
38
srcs/main.c
@@ -6,12 +6,39 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/19 17:08:46 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/07 15:11:58 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 13:47:35 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_env *def_env(void)
|
||||
{
|
||||
t_env *ret;
|
||||
t_env *n;
|
||||
char p[PATH_MAX];
|
||||
|
||||
n = ft_memalloc(sizeof(t_env));
|
||||
if (n != NULL && ((n->key = ft_strnew(3)) == NULL || !getcwd(p, PATH_MAX)))
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_strcpy(n->key, "PWD");
|
||||
if (n != NULL && (n->val = ft_strdup(p)) == NULL)
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_envaddend(&ret, n);
|
||||
n = ft_memalloc(sizeof(t_env));
|
||||
if (n != NULL && (n->key = ft_strnew(5)) == NULL)
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_strcpy(n->key, "SHLVL");
|
||||
if (n != NULL && (n->val = ft_strdup("1")) == NULL)
|
||||
ft_envdelelem(&n);
|
||||
if (n != NULL)
|
||||
ft_envaddend(&ret, n);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char *inc_shlvl(char **shlvl)
|
||||
{
|
||||
char *ret;
|
||||
@@ -32,7 +59,7 @@ t_env *env2lst(char **env)
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
while (env && env[i])
|
||||
while (env[i])
|
||||
{
|
||||
if ((new = ft_envnew(env[i])) != NULL)
|
||||
{
|
||||
@@ -78,15 +105,14 @@ int cleanup(char **argv, t_env *env)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int ac , char **av, char **envp)
|
||||
int main(void)
|
||||
{
|
||||
extern char **environ;
|
||||
char **argv;
|
||||
t_env *env;
|
||||
char *cmd;
|
||||
|
||||
(void)ac;
|
||||
(void)av;
|
||||
if ((env = env2lst(envp)) == NULL)
|
||||
if ((env = env2lst(environ)) == NULL)
|
||||
return (2);
|
||||
while (1)
|
||||
{
|
||||
|
@@ -6,12 +6,32 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/01 15:47:08 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 11:48:25 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int ft_isin(char *str, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str && str[i])
|
||||
if (str[i++] == c)
|
||||
return (i - 1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void *put_error(char *file, char *msg)
|
||||
{
|
||||
ft_putstr("minishell: ");
|
||||
ft_putstr(file);
|
||||
ft_putstr(": ");
|
||||
ft_putendl(msg);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *check_path_slash(char *exec)
|
||||
{
|
||||
int i;
|
||||
@@ -62,6 +82,12 @@ char *check_path_dot(char *exec, t_env *env)
|
||||
return (put_error(exec, "no such file or directory"));
|
||||
}
|
||||
|
||||
void *ft_strdel_null(char **s)
|
||||
{
|
||||
ft_strdel(s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *check_path_elems(char **path_elems, char *exec)
|
||||
{
|
||||
int i;
|
||||
@@ -120,6 +146,17 @@ char *check_path(char *exec, t_env *env)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void exec_cmd_child(char *path, char **argv, char **env_tab, t_env **env)
|
||||
{
|
||||
execve(path, argv, env_tab);
|
||||
ft_putendl_fd("minishell: error", 1);
|
||||
if (ft_strcmp(path, argv[0]) != 0)
|
||||
ft_strdel(&path);
|
||||
ft_del_words_tables(&env_tab);
|
||||
ft_envdel(env);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int exec_cmd(char **argv, t_env **env)
|
||||
{
|
||||
int ret;
|
||||
|
@@ -1,56 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ms_exec_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/02/01 15:43:41 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/01 15:56:49 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void exec_cmd_child(char *path, char **argv, char **env_tab, t_env **env)
|
||||
{
|
||||
execve(path, argv, env_tab);
|
||||
ft_putendl_fd("minishell: error", 1);
|
||||
if (ft_strcmp(path, argv[0]) != 0)
|
||||
ft_strdel(&path);
|
||||
ft_del_words_tables(&env_tab);
|
||||
ft_envdel(env);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void *ft_strdel_null(char **s)
|
||||
{
|
||||
ft_strdel(s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int ft_isin(char *str, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str && str[i])
|
||||
if (str[i++] == c)
|
||||
return (i - 1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void *put_error(char *file, char *msg)
|
||||
{
|
||||
ft_putstr("minishell: ");
|
||||
ft_putstr(file);
|
||||
ft_putstr(": ");
|
||||
ft_putendl(msg);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void *return_null(char *msg)
|
||||
{
|
||||
ft_printf("%s\n", msg);
|
||||
return (NULL);
|
||||
}
|
@@ -6,12 +6,18 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/10/25 18:21:47 by tmaze #+# #+# */
|
||||
/* Updated: 2020/02/07 15:55:59 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 15:42:17 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void *return_null(char *msg)
|
||||
{
|
||||
ft_printf("%s\n", msg);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void ft_strreplace(char **dst, char *src, int *index, t_env *elem)
|
||||
{
|
||||
if (*dst != NULL)
|
||||
@@ -51,11 +57,12 @@ char *replace_env(char *src, t_env *elem, int key_size, int i)
|
||||
int res_len;
|
||||
|
||||
res_len = ft_strlen(src) - key_size + ft_strlen(elem->val);
|
||||
ft_printf("size replace: %d\n", res_len);
|
||||
if ((ret = ft_strnew(res_len)) != NULL)
|
||||
{
|
||||
ft_strncpy(ret, src, i);
|
||||
ft_strlcat(ret, elem->val, res_len + 1);
|
||||
ft_strlcat(ret, &src[i] + key_size, res_len + 1);
|
||||
ft_strlcat(ret, src + key_size, res_len + 1);
|
||||
}
|
||||
else
|
||||
ft_printf("minishell: memory error\n");
|
||||
|
Reference in New Issue
Block a user