J'ai fais des trucs pas comme toi bozo

This commit is contained in:
Etienne Rey-bethbeder 2023-02-21 14:45:43 +01:00
parent 373629b541
commit 73899f5905
4 changed files with 86 additions and 7 deletions

View File

@ -1,5 +1,5 @@
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c builtins/cd.c
OBJS = ${SRCS:.c=.o} OBJS = ${SRCS:.c=.o}

57
builtins/cd.c Normal file
View File

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
/* Updated: 2023/02/21 14:41:58 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int move_folder(char *path, int fd)
{
char *join;
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
{
if (chdir(path) == 0)
return (0);
ft_printf("chdir error");
return (1);
}
else
{
join = ft_strjoin("/", path);
join = ft_strfjoin(get_pwd(fd), join);
if (chdir(join) == 0)
{
free(join);
return (0);
}
free(join);
ft_printf("chdir error");
return (1);
}
}
/*int main(int argc, char *argv[]) {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%s\n", cwd);
} else {
perror("getcwd() error");
return 1;
}
move_folder(argv[1], 1);
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%s\n", cwd);
} else {
perror("getcwd() error");
return 1;
}
return 0;
}*/

View File

@ -6,15 +6,36 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */ /* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
/* Updated: 2023/02/17 17:08:00 by erey-bet ### ########.fr */ /* Updated: 2023/02/21 14:34:50 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../minishell.h" #include "../minishell.h"
int pwd(t_list **env, int fd) int pwd(int fd)
{ {
ft_putstr_fd(get_value_by_key("PWD", env), fd); char path[PATH_MAX];
write(fd, "\n", 1);
if (getcwd(path, sizeof(path)) != NULL)
ft_putstr_fd(path, fd);
else
{
ft_putstr_fd("Error getcwd", fd);
return (1);
}
return (0); return (0);
} }
char *get_pwd(int fd)
{
char *str;
str = ft_calloc(PATH_MAX, sizeof(char *));
if (getcwd(str, PATH_MAX) != NULL)
return (str);
else
{
ft_putstr_fd("Error getcwd", fd);
return (NULL);
}
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */ /* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
/* Updated: 2023/02/21 14:09:21 by cchauvet ### ########.fr */ /* Updated: 2023/02/21 14:43:45 by erey-bet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -60,7 +60,8 @@ char *get_key(char *str);
/* Echo */ /* Echo */
int echo(int fd, char *str); int echo(int fd, char *str);
/* PWD */ /* PWD */
int pwd(t_list **env, int fd); int pwd(int fd);
char *get_pwd(int fd);
/* ENV */ /* ENV */
int print_env(t_list **head, int fd); int print_env(t_list **head, int fd);
/* EXPORT */ /* EXPORT */