maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
exit_status.c File Reference
#include "exit_status.h"
#include "libft.h"
#include <unistd.h>
#include "shell.h"
#include <stdio.h>
Include dependency graph for exit_status.c:

Go to the source code of this file.

Functions

void exit_status_handler (t_ms_data *data, int status_code, char *err_arg)
 
void ft_puterror (char *err_arg, char *error_message)
 
void set_exit_status (int *exit_status, int status_code)
 
void set_shell_var_handler (t_ms_data *data)
 

Function Documentation

◆ exit_status_handler()

void exit_status_handler ( t_ms_data data,
int  status_code,
char *  err_arg 
)

Definition at line 25 of file exit_status.c.

26{
27 char *error_message;
28
29 error_message = NULL;
30 if (status_code == IS_DIRECTORY)
31 error_message = "No such file or directory";
32 else if (status_code == NUMERIC_REQUIRED)
33 error_message = "numeric argument required";
34 else if (status_code == TOO_MANY_ARGS)
35 error_message = "too many arguments";
36 else if (status_code == UNKNOWN_COMMAND)
37 error_message = "command not found";
38 else if (status_code == INVALID_ARGUMENT)
39 error_message = "invalid argument";
40 else if (status_code == PERMISSION_DENIED)
41 error_message = "permission denied";
42 else if (status_code == NOT_VALID_IDENTIFIER)
43 error_message = "unset: not a valid identifier";
44 else if (status_code == INVALID_OPTION)
45 error_message = "invalid option";
46 else
47 error_message = "error";
48 ft_puterror(err_arg, error_message);
49 set_exit_status(&data->exit_status, status_code);
51}
void ft_puterror(char *err_arg, char *error_message)
Definition exit_status.c:62
void set_shell_var_handler(t_ms_data *data)
Definition exit_status.c:53
void set_exit_status(int *exit_status, int status_code)
Definition exit_status.c:78
#define NUMERIC_REQUIRED
Definition exit_status.h:21
#define TOO_MANY_ARGS
Definition exit_status.h:22
#define NOT_VALID_IDENTIFIER
Definition exit_status.h:27
#define INVALID_OPTION
Definition exit_status.h:28
#define PERMISSION_DENIED
Definition exit_status.h:25
#define UNKNOWN_COMMAND
Definition exit_status.h:23
#define INVALID_ARGUMENT
Definition exit_status.h:24
#define IS_DIRECTORY
Definition exit_status.h:20
int exit_status
Definition shell.h:30

References s_ms_data::exit_status, ft_puterror(), INVALID_ARGUMENT, INVALID_OPTION, IS_DIRECTORY, NOT_VALID_IDENTIFIER, NUMERIC_REQUIRED, PERMISSION_DENIED, set_exit_status(), set_shell_var_handler(), TOO_MANY_ARGS, and UNKNOWN_COMMAND.

Referenced by builtin_cd(), builtin_export(), handle_numeric_error(), and handle_too_many_args_error().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_puterror()

void ft_puterror ( char *  err_arg,
char *  error_message 
)

Definition at line 62 of file exit_status.c.

63{
64 if (err_arg)
65 {
66 ft_putstr_fd("bash: ", STDERR_FILENO);
67 ft_putstr_fd(err_arg, STDERR_FILENO);
68 ft_putstr_fd(": ", STDERR_FILENO);
69 ft_putendl_fd(error_message, STDERR_FILENO);
70 }
71 else
72 {
73 ft_putstr_fd("bash: ", STDERR_FILENO);
74 ft_putendl_fd(error_message, STDERR_FILENO);
75 }
76}
void ft_putstr_fd(char *s, int fd)
void ft_putendl_fd(char *s, int fd)

References ft_putendl_fd(), and ft_putstr_fd().

Referenced by exit_status_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_exit_status()

void set_exit_status ( int *  exit_status,
int  status_code 
)

Definition at line 78 of file exit_status.c.

79{
80 *exit_status = status_code;
81}

Referenced by builtin_env(), and exit_status_handler().

Here is the caller graph for this function:

◆ set_shell_var_handler()

void set_shell_var_handler ( t_ms_data data)

Definition at line 53 of file exit_status.c.

54{
55 char *tmp_var;
56
57 tmp_var = ft_itoa(data->exit_status);
58 set_shell_var(&data->shell_variables, "?", tmp_var);
59 free(tmp_var);
60}
void set_shell_var(t_env **shell_var, const char *key, const char *value)
char * ft_itoa(int n)
Definition ft_itoa.c:40
t_env * shell_variables
Definition shell.h:25

References s_ms_data::exit_status, ft_itoa(), set_shell_var(), and s_ms_data::shell_variables.

Referenced by exit_status_handler(), and new_process().

Here is the call graph for this function:
Here is the caller graph for this function: