mirror of
https://github.com/zoriya/ash.git
synced 2026-05-31 01:55:56 +00:00
Merge pull request #71 from AnonymusRaccoon/exit
Exit is working taking care of its code exit
This commit is contained in:
@@ -8,11 +8,13 @@
|
||||
#include "shell.h"
|
||||
#include "builtin.h"
|
||||
#include "redirections.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int run_builtin(const builtin *cmd, char **a, redirection *inout[2], env_t *env)
|
||||
{
|
||||
@@ -63,9 +65,30 @@ int builtin_cd(char **argv, env_t *env)
|
||||
return (0);
|
||||
}
|
||||
|
||||
bool my_strisnum(char *str)
|
||||
{
|
||||
for (int i = 0; str[i]; i++) {
|
||||
if (!isdigit(str[i]))
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
int builtin_exit(char **argv, env_t *env)
|
||||
{
|
||||
if (argv[1])
|
||||
env->vars = my_setenv(env->vars, "?", "1");
|
||||
char *ptr = argv[1];
|
||||
|
||||
if (!ptr) {
|
||||
env->vars = my_setenv(env->vars, "?", "0");
|
||||
return (-1);
|
||||
}
|
||||
if (argv[1][0] == '-') {
|
||||
ptr = &ptr[1];
|
||||
}
|
||||
if (!my_strisnum(ptr)) {
|
||||
dprintf(2, "exit: Expression Syntax.\n");
|
||||
return (0);
|
||||
}
|
||||
env->vars = my_setenv(env->vars, "?", argv[1]);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user