diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-01 21:35:53 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-01 21:35:53 +0100 |
commit | 314f8f2c501322717c247fe512093a894244b702 (patch) | |
tree | 7542a204ffd719f639624f33cfa079063fc98e8c /src | |
parent | commit (diff) | |
download | 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.gz 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.bz2 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.xz 42-minishell-314f8f2c501322717c247fe512093a894244b702.tar.zst 42-minishell-314f8f2c501322717c247fe512093a894244b702.zip |
Merged shotgunfixes
Diffstat (limited to 'src')
-rw-r--r-- | src/b_exit.c | 12 | ||||
-rw-r--r-- | src/b_type.c | 2 | ||||
-rw-r--r-- | src/f_fail.c | 6 | ||||
-rw-r--r-- | src/f_fail.h | 1 |
4 files changed, 15 insertions, 6 deletions
diff --git a/src/b_exit.c b/src/b_exit.c index aa3360d..4f395cf 100644 --- a/src/b_exit.c +++ b/src/b_exit.c @@ -20,10 +20,6 @@ #include "s_struct.h" #include "u_utils.h" -/* -** TODO: handle non-numeric args[0] -*/ - unsigned char b_exit(char *args[], t_msh *msh) { unsigned char ret; @@ -36,7 +32,13 @@ unsigned char b_exit(char *args[], t_msh *msh) } if (argc == 1) { - ret = ft_atoi(args[0]); + if (ft_isfulldigit(args[0])) + ret = ft_atoi(args[0]); + else + { + f_fail_non_numeric_arg("exit", args[0]); + ret = 2; + } } else ret = msh->ret; diff --git a/src/b_type.c b/src/b_type.c index 5904742..789071f 100644 --- a/src/b_type.c +++ b/src/b_type.c @@ -47,7 +47,7 @@ static char b_absolute_path_exists(char com[]) static void b_type_get_path(char fullpath[], char com[], t_msh *msh) { - if (ft_ischarset("/.", com[0]) == TRUE) + if (ft_strchr(com, '/') != NULL) { if (b_absolute_path_exists(com)) { diff --git a/src/f_fail.c b/src/f_fail.c index 7b48b03..d7ac4c4 100644 --- a/src/f_fail.c +++ b/src/f_fail.c @@ -39,3 +39,9 @@ void f_fail_too_many_args(const char concern[], t_msh *msh) { f_write_fail(concern, F_TOO_MANY_ARGS, msh); } + +void f_fail_non_numeric_arg(const char concern[], char *arg) +{ + ft_dprintf(STDERR_FILENO, + "minishell: %s: `%s': numerical argument required\n", concern, arg); +} diff --git a/src/f_fail.h b/src/f_fail.h index 4cc9973..6bf248c 100644 --- a/src/f_fail.h +++ b/src/f_fail.h @@ -27,5 +27,6 @@ void f_fail_no_options(const char concern[], t_msh *msh); void f_fail_too_many_args(const char concern[], t_msh *msh); void f_fail_identifier(const char concern[], const char identifier[]); +void f_fail_non_numeric_arg(const char concern[], char *arg); #endif |