diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-10 19:46:07 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-10 20:32:25 +0200 |
| commit | 98990d5195e93154abbfd16eaa9d1fcc3572bc5c (patch) | |
| tree | 110a4cedf6ada1281cdc356b21ebe2b55acec32a /src/error.c | |
| parent | b16d4b834d95d5cc0757d09e74fe6042e55f5440 (diff) | |
| download | minishell-98990d5195e93154abbfd16eaa9d1fcc3572bc5c.tar.gz minishell-98990d5195e93154abbfd16eaa9d1fcc3572bc5c.tar.bz2 minishell-98990d5195e93154abbfd16eaa9d1fcc3572bc5c.zip | |
Added errorf_ret helper, Removing error to status (just status code and fatal error)
Diffstat (limited to 'src/error.c')
| -rw-r--r-- | src/error.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/error.c b/src/error.c index 6c24635..2e56117 100644 --- a/src/error.c +++ b/src/error.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 11:02:52 by charles #+# #+# */ -/* Updated: 2020/09/10 14:48:19 by charles ### ########.fr */ +/* Updated: 2020/09/10 20:29:41 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ ** \note NULL arguments are ignored */ -void errorf(const char *format, ...) +void errorf(const char *format, ...) { va_list ap; @@ -28,7 +28,11 @@ void errorf(const char *format, ...) va_end(ap); } -void verrorf(const char *format, va_list ap) +/* +** \brief errorf with an argument pointer (ap) instead of arguments +*/ + +void verrorf(const char *format, va_list ap) { char *arg; @@ -50,28 +54,16 @@ void verrorf(const char *format, va_list ap) } } -static int g_error_to_status[] = { - [ERR_NONE] = 0, - [ERR_AMBIGUOUS_REDIR] = 1, - [ERR_OPEN] = 1, - [ERR_CMD_NOT_FOUND] = 127, - [ERR_SYNTAX] = 2, - [ERR_IS_DIRECTORY] = 126, - [ERR_ERRNO] = 126, -}; +/* +** \brief errorf helper to return an status code and print the error +*/ -int error_get_status(int status) +int errorf_ret(int status, const char *format, ...) { - return (g_error_to_status[status]); -} + va_list ap; -void error_set_status(int status) -{ - if (status == ERR_FATAL) - exit(1); - /* printf("%d\n", status); */ - if (status < ERR_NONE) - g_last_status = status; - else - g_last_status = g_error_to_status[status]; + va_start(ap, format); + verrorf(format, ap); + va_end(ap); + return (status); } |
