AAAAAAAAAAAa les headers
This commit is contained in:
15
Makefile
15
Makefile
@ -1,6 +1,19 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||
# Updated: 2024/02/16 21:56:22 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
CC = cc
|
||||
SRCS_RAW = main.c\
|
||||
lst_cmd.c\
|
||||
cd.c\
|
||||
lst_env.c\
|
||||
exec.c\
|
||||
exit.c\
|
||||
@ -16,6 +29,7 @@ OBJS_DIR = objs/
|
||||
SRCS_DIR = srcs/
|
||||
SRCS = $(addprefix $(SRCS_DIR), $(SRCS_RAW))
|
||||
OBJS = $(addprefix $(OBJS_DIR), $(SRCS_RAW:.c=.o))
|
||||
|
||||
FLAGS = -Wall -Wextra -Werror -g
|
||||
LIBFT = libft/libft.a
|
||||
NAME = minishell
|
||||
@ -45,4 +59,3 @@ fclean: clean
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
|
||||
|
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);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/16 21:52:02 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/16 21:56:40 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,6 +25,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,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/16 21:29:05 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/16 21:57:11 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Reference in New Issue
Block a user