maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
env.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* env.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/06/07 17:20:11 by dmdemirk #+# #+# */
9/* Updated: 2024/06/26 14:48:35 by dmdemirk ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "shell.h"
14#include "env.h"
15#include "libft.h"
16#include <stdlib.h>
17#include <stdio.h>
18#include "exit_status.h"
19
20void print_env_stack(t_env *envp);
21int builtin_env(t_ms_data *data);
22
24{
25 t_env *curr_node;
26
27 curr_node = envp;
28 while (curr_node)
29 {
30 ft_printf("%s=%s\n", curr_node->key, curr_node->value);
31 curr_node = curr_node->next;
32 }
33}
34
36{
37 if (ft_strcmp(data->args[0], "env") == 0 && data->args[1] == NULL)
38 print_env_stack(data->envp);
39 else
40 {
41 ft_putstr_fd("env: '", STDERR_FILENO);
42 ft_putstr_fd(data->args[1], STDERR_FILENO);
43 ft_putstr_fd("': No such file or directory\n", STDERR_FILENO);
46 return (IS_DIRECTORY);
47 }
48 return (EXIT_SUCCESS);
49}
void print_env_stack(t_env *envp)
Definition env.c:23
int builtin_env(t_ms_data *data)
Definition env.c:35
void set_shell_var(t_env **shell_var, const char *key, const char *value)
#define EXIT_SUCCESS
Definition exit_status.h:16
void set_exit_status(int *exit_status, int status_code)
Definition exit_status.c:78
#define IS_DIRECTORY
Definition exit_status.h:20
int ft_printf(const char *format,...)
Definition ft_printf.c:37
int ft_strcmp(const char *s1, const char *s2)
Definition ft_strcmp.c:24
char * ft_itoa(int n)
Definition ft_itoa.c:40
void ft_putstr_fd(char *s, int fd)
Definition env.h:17
struct s_env * next
Definition env.h:20
char * key
Definition env.h:18
char * value
Definition env.h:19
int exit_status
Definition shell.h:30
t_env * envp
Definition shell.h:24
t_env * shell_variables
Definition shell.h:25
char ** args
Definition shell.h:23