working on cd
This commit is contained in:
6
Makefile
6
Makefile
@ -6,7 +6,7 @@
|
||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||
# Updated: 2024/02/16 21:24:47 by tomoron ### ########.fr #
|
||||
# Updated: 2024/02/16 21:31:30 by marde-vr ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,7 @@ SRCS = main.c\
|
||||
exit.c\
|
||||
echo.c\
|
||||
pwd.c\
|
||||
cd.c\
|
||||
parsing.c\
|
||||
debug.c\
|
||||
env_to_char_tab.c\
|
||||
@ -27,8 +28,6 @@ SRCS = main.c\
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
OBJS_DIR = objs
|
||||
|
||||
FLAGS = -Wall -Wextra -Werror -g
|
||||
|
||||
LIBFT = libft/libft.a
|
||||
@ -38,7 +37,6 @@ NAME = minishell
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME) : $(LIBFT) $(OBJS)
|
||||
mkdir $(OBJS_DIR)
|
||||
$(CC) $(FLAGS) $(OBJS) $(LIBFT) -lreadline -o $(NAME)
|
||||
|
||||
$(LIBFT):
|
||||
|
37
cd.c
Normal file
37
cd.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/02/16 21:51:28 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int cd(t_cmd *args, t_env *env)
|
||||
{
|
||||
char *cwd;
|
||||
char *new_wd;
|
||||
|
||||
cwd = getcwd(0, 0);
|
||||
if (args->next->next && args->next->next->type == ARG)
|
||||
{
|
||||
ft_printf_fd(2, "minishell: cd: too many arguments\n");
|
||||
return (1);
|
||||
}
|
||||
if (!args->next || args->next->type != ARG)
|
||||
new_wd = ft_get_env(env, "HOME");
|
||||
else
|
||||
{
|
||||
new_wd = args->next->token;
|
||||
if (chdir(new_wd) == -1)
|
||||
perror("chdir");
|
||||
}
|
||||
ft_putstr(cwd);
|
||||
(void)args;
|
||||
return (0);
|
||||
}
|
4
exec.c
4
exec.c
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/16 17:26:04 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/16 21:20:57 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -27,6 +27,8 @@ int exec_builtin(t_cmd *parsed_cmd, t_env *env)
|
||||
exit_bt(parsed_cmd, env);
|
||||
else if (!ft_strcmp(parsed_cmd->token, "pwd"))
|
||||
g_return_code = pwd();
|
||||
else if (!ft_strcmp(parsed_cmd->token, "cd"))
|
||||
g_return_code = cd(parsed_cmd);
|
||||
else
|
||||
return (STDIN_FILENO);
|
||||
return (STDOUT_FILENO);
|
||||
|
6
main.c
6
main.c
@ -6,11 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
<<<<<<< HEAD
|
||||
/* Updated: 2024/02/16 16:37:13 by tomoron ### ########.fr */
|
||||
=======
|
||||
/* Updated: 2024/02/16 18:21:27 by marde-vr ### ########.fr */
|
||||
>>>>>>> ad1de58fb2aacb8a3b1b7ef5d74fc6d87f4550b2
|
||||
/* Updated: 2024/02/16 21:30:50 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user