Skip to content

Commit

Permalink
Custom status added
Browse files Browse the repository at this point in the history
  • Loading branch information
davixcky committed Apr 18, 2020
1 parent 7015f3f commit c57c491
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ int check_builtin(general_t *info, char **arguments);

/* exit.c */
void bin_exit(general_t *info, char **arguments);
int number_controller(general_t *info, char *number);

/* env.c */
void bin_env(general_t *info, char **arguments);
Expand Down
32 changes: 31 additions & 1 deletion exit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "builtins.h"
#include "general.h"

/**
* bin_exit - Implementation of the exit builtin
Expand All @@ -10,7 +11,14 @@
**/
void bin_exit(general_t *info, char **arguments)
{
int status_code;
int status_code, status;

status = _TRUE;
if (arguments[1] != NULL)
status = number_controller(info, arguments[1]);

if (status == _FALSE)
return;

status_code = info->status_code;

Expand All @@ -22,3 +30,25 @@ void bin_exit(general_t *info, char **arguments)
exit(status_code);
}

int number_controller(general_t *info, char *number)
{
int _number;

_number = _atoi(number);

if (_number < 0 || contains_letter(number))
{
info->status_code = 2;
info->error_code = _CODE_ILLEGAL_NUMBER;
error(info);
return (_FALSE);
}

if (_number > 255)
info->status_code = 232;

printf("%d\n", _number);

return (_TRUE);
}

0 comments on commit c57c491

Please sign in to comment.