Merge branch 'feature/builtins' into develop
This commit is contained in:
30
include/builtins.h
Normal file
30
include/builtins.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* builtins.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/10/29 22:09:51 by sede-san #+# #+# */
|
||||||
|
/* Updated: 2025/10/30 12:06:39 by sede-san ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef BUILTINS_H
|
||||||
|
# define BUILTINS_H
|
||||||
|
|
||||||
|
# include "minishell.h"
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* Functions */
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// exit.c
|
||||||
|
|
||||||
|
extern u_int8_t builtin_exit(t_command cmd, t_minishell *msh);
|
||||||
|
|
||||||
|
// pwd.c
|
||||||
|
|
||||||
|
extern u_int8_t builtin_pwd(t_command cmd, t_minishell *msh);
|
||||||
|
|
||||||
|
#endif /* BUILTINS_H */
|
||||||
44
src/builtins/exit/exit.c
Normal file
44
src/builtins/exit/exit.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* exit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/10/30 01:20:48 by sede-san #+# #+# */
|
||||||
|
/* Updated: 2025/10/30 09:08:02 by sede-san ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "builtins.h"
|
||||||
|
|
||||||
|
u_int8_t builtin_exit(
|
||||||
|
t_command cmd,
|
||||||
|
t_minishell *msh
|
||||||
|
){
|
||||||
|
ft_eputendl("exit");
|
||||||
|
if (cmd.argc == 1)
|
||||||
|
{
|
||||||
|
// msh.exit = 1;
|
||||||
|
// return the last exit_status, if none 0 is returned
|
||||||
|
return (msh->exit_status);
|
||||||
|
}
|
||||||
|
else if (!ft_strisnum(cmd.argv[1]))
|
||||||
|
{
|
||||||
|
ft_eputstr("exit: ");
|
||||||
|
ft_eputendl(cmd.argv[1]);
|
||||||
|
ft_eputendl(": numeric argument required");
|
||||||
|
return (2);
|
||||||
|
}
|
||||||
|
else if (cmd.argc > 2)
|
||||||
|
{
|
||||||
|
ft_eputendl("exit: too many arguments");
|
||||||
|
return (2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// msh.exit = 1;
|
||||||
|
// cast to u_int8_t causes to return a value between 0 and 255
|
||||||
|
return ((u_int8_t)ft_atol(cmd.argv[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/builtins/pwd/pwd.c
Normal file
26
src/builtins/pwd/pwd.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* pwd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/10/29 22:08:55 by sede-san #+# #+# */
|
||||||
|
/* Updated: 2025/10/30 01:14:09 by sede-san ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "builtins.h"
|
||||||
|
|
||||||
|
u_int8_t builtin_pwd(
|
||||||
|
t_command cmd,
|
||||||
|
t_minishell *msh
|
||||||
|
){
|
||||||
|
char cwd[PATH_MAX];
|
||||||
|
|
||||||
|
(void)cmd;
|
||||||
|
(void)msh;
|
||||||
|
getcwd(cwd, PATH_MAX);
|
||||||
|
printf("%s\n", cwd);
|
||||||
|
return (EXIT_SUCCESS);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user