Repository: cacapon/minishell
Pull request #210: 191 invoke cmd handle built in command
Author: login: dayano74
Created: 2025-05-04T09:20:59Z | Merged: 2025-05-04T11:44:03Z

ビルトインのコマンドを実行する処理を追加しました。
`./minishell`で試してください。

builtinのexitがargcが1のときしか許していなかったので、argcが2の時も動作するようにしました。
argc=2の時も実行できる処理を実装するため、fd_strtolとfd_strtollを追加しました。


Diff:
diff --git a/inc/invoke_cmd/execute_cmd.h b/inc/invoke_cmd/execute_cmd.h
index 9ca7f11..d8c0705 100644
--- a/inc/invoke_cmd/execute_cmd.h
+++ b/inc/invoke_cmd/execute_cmd.h
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   execute_cmd.h                                      :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ttsubo <ttsubo@student.42.fr>              +#+  +:+       +#+        */
+/*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/21 21:39:18 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/04 13:15:50 by ttsubo           ###   ########.fr       */
+/*   Updated: 2025/05/04 18:31:58 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -15,6 +15,7 @@
 
 # define PATH_PREFIX_LEN 5
 
+# define INCORRECT_USAGE 2
 # define CMD_FAILED_EXIT_STATUS 126
 # define CMD_NOT_FOUND_EXIT_STATUS 127
 
diff --git a/inc/invoke_cmd/invoke_command.h b/inc/invoke_cmd/invoke_command.h
index 7e9d22c..85bb430 100644
--- a/inc/invoke_cmd/invoke_command.h
+++ b/inc/invoke_cmd/invoke_command.h
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   invoke_command.h                                   :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ttsubo <ttsubo@student.42.fr>              +#+  +:+       +#+        */
+/*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/20 21:21:13 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/04 12:37:03 by ttsubo           ###   ########.fr       */
+/*   Updated: 2025/05/04 18:32:13 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -24,6 +24,7 @@
 
 int		invoke_commands(t_cmd *cmd_head, t_minish *minish);
 int		exec_unit_builtin(t_cmd *cmd, t_minish *minish);
+int		execute_builtin(t_cmd *cmd, t_minish *minish);
 
 // wait_pipeline.c
 int		wait_pipeline(t_cmd *cmd_head);
diff --git a/lib/libft/Makefile b/lib/libft/Makefile
index 1d18d6d..beae0f5 100644
--- a/lib/libft/Makefile
+++ b/lib/libft/Makefile
@@ -3,10 +3,10 @@
 #                                                         :::      ::::::::    #
 #    Makefile                                           :+:      :+:    :+:    #
 #                                                     +:+ +:+         +:+      #
-#    By: ttsubo <ttsubo@student.42.fr>              +#+  +:+       +#+         #
+#    By: dayano <dayano@student.42.fr>              +#+  +:+       +#+         #
 #                                                 +#+#+#+#+#+   +#+            #
 #    Created: 2024/11/06 10:03:51 by ttsubo            #+#    #+#              #
-#    Updated: 2025/04/17 16:32:30 by ttsubo           ###   ########.fr        #
+#    Updated: 2025/05/04 17:33:14 by dayano           ###   ########.fr        #
 #                                                                              #
 # **************************************************************************** #
 
@@ -33,7 +33,8 @@ SRCS	= 	ft_atoi.c     ft_isdigit.c  ft_memmove.c     ft_split.c     ft_strlcpy.c
 			ft_max.c	  ft_min.c		ft_abs.c	ft_strnlen.c	ft_strlen_until.c \
 			ft_lstnew.c	ft_lstadd_front.c	ft_lstsize.c	ft_lstlast.c	ft_lstadd_back.c		\
 			ft_lstdelone.c	ft_lstclear.c	ft_lstiter.c	ft_lstmap.c		ft_strcmp.c				\
-			ft_max.c	  ft_min.c		ft_abs.c	ft_strnlen.c	ft_strlen_until.c	ft_isspace.c
+			ft_max.c	  ft_min.c		ft_abs.c	ft_strnlen.c	ft_strlen_until.c	ft_isspace.c	\
+			ft_strtoll.c  ft_strtol.c
 
 ifeq ($(MAKECMDGOALS), debug)
 	CC := gcc -Wall -Wextra -Werror -g
diff --git a/lib/libft/ft_strtol.c b/lib/libft/ft_strtol.c
new file mode 100644
index 0000000..cf858b7
--- /dev/null
+++ b/lib/libft/ft_strtol.c
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strtol.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/03/07 20:43:11 by dayano            #+#    #+#             */
+/*   Updated: 2025/05/04 17:29:50 by dayano           ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+
+long	ft_strtol(const char *nptr, char **endptr, int base)
+{
+	return ((long)ft_strtoll(nptr, endptr, base));
+}
diff --git a/lib/libft/ft_strtoll.c b/lib/libft/ft_strtoll.c
new file mode 100644
index 0000000..cbe73f4
--- /dev/null
+++ b/lib/libft/ft_strtoll.c
@@ -0,0 +1,122 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strtoll.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/03/09 21:02:46 by dayano            #+#    #+#             */
+/*   Updated: 2025/05/04 17:30:03 by dayano           ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include <errno.h>
+#include <limits.h>
+#include <stddef.h>
+
+static int	parse_base_and_sign(const char **str, int base, int *sign)
+{
+	*sign = 1;
+	if (**str == '-' || **str == '+')
+	{
+		if (**str == '-')
+			*sign = -1;
+		(*str)++;
+	}
+	if (base == 0)
+	{
+		if (**str == '0')
+		{
+			(*str)++;
+			if (**str == 'x' || **str == 'X')
+			{
+				(*str)++;
+				return (16);
+			}
+			return (8);
+		}
+		return (10);
+	}
+	if (base == 16 && **str == '0' && (*(*str + 1) == 'x' || *(*str
+				+ 1) == 'X'))
+		*str += 2;
+	return (base);
+}
+
+static int	convert_digit(char c, int base)
+{
+	const char	*digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+	const char	*p;
+
+	p = ft_strchr(digits, ft_toupper(c));
+	if (p && p - digits < base)
+		return (p - digits);
+	return (-1);
+}
+
+static void	handle_overflow(const char **str, int base,
+		unsigned long long *result, int sign)
+{
+	errno = ERANGE;
+	*result = (unsigned long long)LLONG_MAX + ((1 - sign) >> 1);
+	while (convert_digit(**str, base) >= 0)
+		(*str)++;
+}
+
+static long long	process_digits(const char **str, int base, int sign,
+		char **endptr)
+{
+	unsigned long long	result;
+	unsigned long long	cutoff;
+	int					cutlim;
+	int					digit;
+
+	result = 0;
+	cutoff = (unsigned long long)LLONG_MAX + ((1 - sign) >> 1);
+	cutlim = cutoff % base;
+	cutoff /= base;
+	while (1)
+	{
+		digit = convert_digit(**str, base);
+		if (digit < 0)
+			break ;
+		if (result > cutoff || (result == cutoff && digit > cutlim))
+		{
+			handle_overflow(str, base, &result, sign);
+			break ;
+		}
+		result = result * base + digit;
+		(*str)++;
+	}
+	if (endptr)
+		*endptr = (char *)*str;
+	return ((long long)sign * (long long)result);
+}
+
+long long	ft_strtoll(const char *nptr, char **endptr, int base)
+{
+	const char	*str;
+	int			sign;
+	long long	result;
+
+	if (base < 0 || base == 1 || base > 36)
+	{
+		errno = EINVAL;
+		if (endptr)
+			*endptr = (char *)nptr;
+		return (0);
+	}
+	while (ft_isspace(*nptr))
+		nptr++;
+	str = nptr;
+	base = parse_base_and_sign(&str, base, &sign);
+	result = process_digits(&str, base, sign, endptr);
+	if (str == nptr)
+	{
+		if (endptr)
+			*endptr = (char *)nptr;
+		return (0);
+	}
+	return (result);
+}
diff --git a/lib/libft/libft.h b/lib/libft/libft.h
index 9a28f09..ad5bdc5 100644
--- a/lib/libft/libft.h
+++ b/lib/libft/libft.h
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   libft.h                                            :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ttsubo <ttsubo@student.42.fr>              +#+  +:+       +#+        */
+/*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/10/28 11:41:08 by ttsubo            #+#    #+#             */
-/*   Updated: 2025/04/17 16:30:51 by ttsubo           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:34:18 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -40,6 +40,8 @@ char				*ft_strnstr(const char *big, const char *little,
 						size_t len);
 char				*ft_strrchr(const char *s, int c);
 char				*ft_strtrim(char const *s1, char const *set);
+long				ft_strtol(const char *nptr, char **endptr, int base);
+long long			ft_strtoll(const char *nptr, char **endptr, int base);
 char				*ft_substr(char const *s, unsigned int start, size_t len);
 int					ft_atoi(const char *str);
 int					ft_isalnum(int c);
diff --git a/src/builtin/exit.c b/src/builtin/exit.c
index ff0dbaa..409c370 100644
--- a/src/builtin/exit.c
+++ b/src/builtin/exit.c
@@ -6,7 +6,7 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/13 21:20:48 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/01 15:50:02 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 18:34:59 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,10 +14,23 @@
 
 int	builtin_exit(int argc, char *argv[], t_minish *minish)
 {
+	long	status;
+	char	*endptr;
+
 	(void)minish;
-	if (argc != 1)
+	if (argc > 2)
 		return (error_mes(argv[0], "too many arguments"), EXIT_FAILURE);
 	if (printf("exit\n") < 0)
 		return (perror("printf"), EXIT_FAILURE);
-	exit(EXIT_SUCCESS);
+	if (argc == 1)
+		exit(EXIT_SUCCESS);
+	errno = 0;
+	status = ft_strtol(argv[1], &endptr, 10);
+	if (errno != 0 || *endptr != '\0')
+	{
+		ft_putstr_fd("minishell: exit: ", STDERR_FILENO);
+		error_mes(argv[1], "numeric argument required");
+		exit(INCORRECT_USAGE);
+	}
+	exit((unsigned int)status);
 }
diff --git a/src/invoke_cmd/exec_pipeline.c b/src/invoke_cmd/exec_pipeline.c
index 036488b..a986f15 100644
--- a/src/invoke_cmd/exec_pipeline.c
+++ b/src/invoke_cmd/exec_pipeline.c
@@ -6,7 +6,7 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/21 13:14:15 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/01 16:51:13 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 18:14:21 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -57,7 +57,7 @@ static pid_t	_fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds,
 	if ((cmd->next != NULL) && is_redirect(cmd->next))
 		redirect(cmd->next);
 	if (is_builtin(cmd))
-		exit(exec_unit_builtin(cmd, minish));
+		exit(execute_builtin(cmd, minish));
 	execute_cmd(cmd, minish);
 	print_error(cmd->argv[0]);
 	exit(EXIT_FAILURE);
diff --git a/src/invoke_cmd/execute_cmd_helper.c b/src/invoke_cmd/execute_cmd_helper.c
index c3ba59b..72f7f1e 100644
--- a/src/invoke_cmd/execute_cmd_helper.c
+++ b/src/invoke_cmd/execute_cmd_helper.c
@@ -6,7 +6,7 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/21 21:37:20 by dayano            #+#    #+#             */
-/*   Updated: 2025/04/25 20:50:51 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:04:58 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,10 +14,10 @@
 
 void	print_cmd_not_found(t_cmd *cmd)
 {
-	ft_putstr_fd("minish: ", STDERR_FILENO);
 	ft_putstr_fd(cmd->argv[0], STDERR_FILENO);
-	ft_putstr_fd(": command not found", STDERR_FILENO);
+	ft_putstr_fd(": command not found\n", STDERR_FILENO);
 	cmd->status = CMD_NOT_FOUND_EXIT_STATUS;
+	exit(CMD_NOT_FOUND_EXIT_STATUS);
 }
 
 void	free_str_array(char **str)
diff --git a/src/invoke_cmd/invoke_command.c b/src/invoke_cmd/invoke_command.c
index 8aba975..5746120 100644
--- a/src/invoke_cmd/invoke_command.c
+++ b/src/invoke_cmd/invoke_command.c
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   invoke_command.c                                   :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: ttsubo <ttsubo@student.42.fr>              +#+  +:+       +#+        */
+/*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/20 21:19:33 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/01 17:07:37 by ttsubo           ###   ########.fr       */
+/*   Updated: 2025/05/04 18:11:39 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -35,7 +35,7 @@ static bool	is_unit_builtin(t_cmd *cmd_head)
 		return (false);
 }
 
-static int	_execute_builtin(t_cmd *cmd, t_minish *minish)
+int	execute_builtin(t_cmd *cmd, t_minish *minish)
 {
 	static const t_builtin	builtin_funcs[] = {
 		builtin_echo, builtin_pwd, builtin_exit, builtin_cd,
@@ -83,7 +83,7 @@ int	exec_unit_builtin(t_cmd *cmd, t_minish *minish)
 	}
 	if (cmd->next && is_redirect(cmd->next))
 		redirect(cmd->next);
-	return (_execute_builtin(builtin_cmd, minish));
+	return (execute_builtin(builtin_cmd, minish));
 }
 
 /**


Reviews:
user: login: cacapon
body: コメントの回答を見てApproveにします。
state: COMMENTED
author_association: OWNER
submitted_at: 2025-05-04T09:40:05Z
user: login: dayano74
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-04T09:46:25Z
user: login: cacapon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-05-04T09:47:06Z
user: login: dayano74
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-04T09:49:42Z
user: login: cacapon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-05-04T09:52:49Z
user: login: dayano74
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-04T11:19:01Z
user: login: cacapon
state: COMMENTED
author_association: OWNER
submitted_at: 2025-05-04T11:43:25Z
user: login: cacapon
body: 疑問点について理解できました。回答ありがとうございます。
OKだと思うのでマージさせていただきますね。お疲れ様でした！
state: APPROVED
author_association: OWNER
submitted_at: 2025-05-04T11:43:58Z

Review comments:
diff_hunk: @@ -6,18 +6,31 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/13 21:20:48 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/01 15:50:02 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:54:32 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "main.h"
 
 int	builtin_exit(int argc, char *argv[], t_minish *minish)
 {
+	long status;
+	char *endptr;
+
 	(void)minish;
-	if (argc != 1)
+	if (argc > 2)
 		return (error_mes(argv[0], "too many arguments"), EXIT_FAILURE);
 	if (printf("exit\n") < 0)
 		return (perror("printf"), EXIT_FAILURE);
-	exit(EXIT_SUCCESS);
+	if(argc == 1)
+		exit(EXIT_SUCCESS);
+	errno = 0;
+	status = ft_strtol(argv[1], &endptr, 10);
path: src/builtin/exit.c
user: login: cacapon
body: exitステータスって0-255までってなっていると思うんですけど、
なぜlong型のstatusとstrtolが必要になったのでしょうか？

created_at: 2025-05-04T09:29:47Z
author_association: OWNER
diff_hunk: @@ -57,7 +57,7 @@ static pid_t	_fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds,
 	if ((cmd->next != NULL) && is_redirect(cmd->next))
 		redirect(cmd->next);
 	if (is_builtin(cmd))
-		exit(exec_unit_builtin(cmd, minish));
+		exit(execute_builtin(cmd, minish));
path: src/invoke_cmd/exec_pipeline.c
user: login: cacapon
body: ここexecute_builtinに変えていますが、元のexec_init_builtinから変えて大丈夫ですか？
exec_init_builtinではリダイレクトの確認とかもしてましたけど…
created_at: 2025-05-04T09:31:22Z
author_association: OWNER
diff_hunk: @@ -6,18 +6,18 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/21 21:37:20 by dayano            #+#    #+#             */
-/*   Updated: 2025/04/25 20:50:51 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:04:58 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "main.h"
 
 void	print_cmd_not_found(t_cmd *cmd)
 {
-	ft_putstr_fd("minish: ", STDERR_FILENO);
path: src/invoke_cmd/execute_cmd_helper.c
user: login: cacapon
body: minish:は出さなくなったんですね。
シェルを出すやつ(exportとか)出さないやつ(catとかlsとか)ありましたけど
この辺は別で対応が必要になる感じですかね？
created_at: 2025-05-04T09:39:34Z
author_association: OWNER
diff_hunk: @@ -57,7 +57,7 @@ static pid_t	_fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds,
 	if ((cmd->next != NULL) && is_redirect(cmd->next))
 		redirect(cmd->next);
 	if (is_builtin(cmd))
-		exit(exec_unit_builtin(cmd, minish));
+		exit(execute_builtin(cmd, minish));
path: src/invoke_cmd/exec_pipeline.c
user: login: dayano74
body: 直前の57、58行目でリダイレクトの確認を行っているので、同じ処理を2度する意味はないと判断し削除しました。
created_at: 2025-05-04T09:46:25Z
author_association: COLLABORATOR
diff_hunk: @@ -57,7 +57,7 @@ static pid_t	_fork_command(t_cmd *cmd, t_cmd *cmd_head, t_pipe_io *pipefds,
 	if ((cmd->next != NULL) && is_redirect(cmd->next))
 		redirect(cmd->next);
 	if (is_builtin(cmd))
-		exit(exec_unit_builtin(cmd, minish));
+		exit(execute_builtin(cmd, minish));
path: src/invoke_cmd/exec_pipeline.c
user: login: cacapon
body: 了解です、でしたらこちらはexecute_builtinで大丈夫そうですね。
Resolveにします。
created_at: 2025-05-04T09:47:06Z
author_association: OWNER
diff_hunk: @@ -6,18 +6,18 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/21 21:37:20 by dayano            #+#    #+#             */
-/*   Updated: 2025/04/25 20:50:51 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:04:58 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "main.h"
 
 void	print_cmd_not_found(t_cmd *cmd)
 {
-	ft_putstr_fd("minish: ", STDERR_FILENO);
path: src/invoke_cmd/execute_cmd_helper.c
user: login: dayano74
body: minish:(bash:)を出力するかしないか違いがわかっておらず、今回は出力の必要がなかったので、削除しました。
必要な場合は追加すればいいと考えております。
created_at: 2025-05-04T09:49:42Z
author_association: COLLABORATOR
diff_hunk: @@ -6,18 +6,18 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/21 21:37:20 by dayano            #+#    #+#             */
-/*   Updated: 2025/04/25 20:50:51 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:04:58 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "main.h"
 
 void	print_cmd_not_found(t_cmd *cmd)
 {
-	ft_putstr_fd("minish: ", STDERR_FILENO);
path: src/invoke_cmd/execute_cmd_helper.c
user: login: cacapon
body: なるほど、cmd_not_foundでは出してなかったからはずしたって感じですね。理解できました
こちらもResolveにします。
created_at: 2025-05-04T09:52:49Z
author_association: OWNER
diff_hunk: @@ -6,18 +6,31 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/13 21:20:48 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/01 15:50:02 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:54:32 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "main.h"
 
 int	builtin_exit(int argc, char *argv[], t_minish *minish)
 {
+	long status;
+	char *endptr;
+
 	(void)minish;
-	if (argc != 1)
+	if (argc > 2)
 		return (error_mes(argv[0], "too many arguments"), EXIT_FAILURE);
 	if (printf("exit\n") < 0)
 		return (perror("printf"), EXIT_FAILURE);
-	exit(EXIT_SUCCESS);
+	if(argc == 1)
+		exit(EXIT_SUCCESS);
+	errno = 0;
+	status = ft_strtol(argv[1], &endptr, 10);
path: src/builtin/exit.c
user: login: dayano74
body: ユーザーが入力した文字列が数値かどうか、あるいは範囲を超えていないかを正確に検証するには、strtolが適していると判断したからです。atoiだと失敗した時、 0をリターンするため、atoi("foo")とatoi(0)の区別がつかないです。strtolのリターン値の値がlong型のため、long型のstatusとstrtolが必要となりました。
created_at: 2025-05-04T10:06:50Z
author_association: COLLABORATOR
diff_hunk: @@ -6,18 +6,31 @@
 /*   By: dayano <dayano@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/04/13 21:20:48 by dayano            #+#    #+#             */
-/*   Updated: 2025/05/01 15:50:02 by dayano           ###   ########.fr       */
+/*   Updated: 2025/05/04 17:54:32 by dayano           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "main.h"
 
 int	builtin_exit(int argc, char *argv[], t_minish *minish)
 {
+	long status;
+	char *endptr;
+
 	(void)minish;
-	if (argc != 1)
+	if (argc > 2)
 		return (error_mes(argv[0], "too many arguments"), EXIT_FAILURE);
 	if (printf("exit\n") < 0)
 		return (perror("printf"), EXIT_FAILURE);
-	exit(EXIT_SUCCESS);
+	if(argc == 1)
+		exit(EXIT_SUCCESS);
+	errno = 0;
+	status = ft_strtol(argv[1], &endptr, 10);
path: src/builtin/exit.c
user: login: cacapon
body: ちょっと理解が追いついてなかったけど、検証してやっと理解できました。
ft_strtolは失敗した時にendptrに入力した文字列が入るんですね。
で、後続のチェックでできるからft_atoiじゃなくてft_strtolが必要になると

とりあえずわかりましたので、Approveします。
created_at: 2025-05-04T11:43:25Z
author_association: OWNER

PR comments:
user: login: cacapon
created_at: 2025-05-04T09:25:36Z
body: レビューは続けますので、resolveの解消はお願いします〜
author_association: OWNER
user: login: dayano74
created_at: 2025-05-04T09:36:21Z
body: > レビューは続けますので、resolveの解消はお願いします〜

解消できました。
author_association: COLLABORATOR