-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dmitry Demirkylych
committed
Jun 17, 2024
1 parent
52e80ce
commit 48399c3
Showing
14 changed files
with
195 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* pwd.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/17 11:10:33 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/17 11:10:42 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "shell.h" | ||
#include <unistd.h> | ||
#include "libft.h" | ||
#include <stdio.h> | ||
|
||
/* | ||
Functionality: | ||
- Print the current working directory | ||
*/ | ||
Functionality: | ||
- Print the current working directory | ||
*/ | ||
|
||
int builtin_pwd(t_minishell_data *data) | ||
int builtin_pwd(t_minishell_data *data) | ||
{ | ||
char cwd[4096]; | ||
char cwd[4096]; | ||
|
||
(void)data; | ||
if (getcwd(cwd, sizeof(cwd)) != NULL) | ||
ft_putendl_fd(cwd, STDOUT_FILENO); | ||
else | ||
{ | ||
(void)data; | ||
if (getcwd(cwd, sizeof(cwd)) != NULL) | ||
ft_putendl_fd(cwd, STDOUT_FILENO); | ||
else | ||
{ | ||
ft_putstr_fd("bash: cd: ", 2); | ||
perror("cwd"); | ||
return (1); | ||
} | ||
return (0); | ||
} | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* unset.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/17 11:10:03 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/17 11:10:25 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "shell.h" | ||
#include "env.h" | ||
#include "libft.h" | ||
#include <unistd.h> | ||
|
||
/* | ||
todo | ||
set the exit status to 1 if the variable is not a valid identifier | ||
Functionality: | ||
- Unset the environment variable | ||
- Return 1 if the variable is not a valid identifier | ||
*/ | ||
todo | ||
set the exit status to 1 if the variable is not a valid identifier | ||
Functionality: | ||
- Unset the environment variable | ||
- Return 1 if the variable is not a valid identifier | ||
*/ | ||
|
||
int builtin_unset(t_minishell_data *data) | ||
int builtin_unset(t_minishell_data *data) | ||
{ | ||
int i; | ||
int ret; | ||
int i; | ||
int ret; | ||
|
||
i = 0; | ||
ret = 0; | ||
while (data->args[++i]) | ||
{ | ||
if (unset_env(&data->envp, data->args[i]) == -1) | ||
{ | ||
ft_putstr_fd("bash: unset: `", STDERR_FILENO); | ||
ft_putstr_fd(data->args[i], STDERR_FILENO); | ||
ft_putendl_fd("': not a valid identifier", STDERR_FILENO); | ||
ret = 1; | ||
} | ||
} | ||
data->exit_status = ret; | ||
return (ret); | ||
} | ||
i = 0; | ||
ret = 0; | ||
while (data->args[++i]) | ||
{ | ||
if (unset_env(&data->envp, data->args[i]) == -1) | ||
{ | ||
ft_putstr_fd("bash: unset: `", STDERR_FILENO); | ||
ft_putstr_fd(data->args[i], STDERR_FILENO); | ||
ft_putendl_fd("': not a valid identifier", STDERR_FILENO); | ||
ret = 1; | ||
} | ||
} | ||
data->exit_status = ret; | ||
return (ret); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.