-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuiltin.c
64 lines (56 loc) · 1.06 KB
/
builtin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "ssh.h"
/**
* b_exit - exit function buitlin
* @av: Array of command arguments.
* @l_ret: Pointer to number of the last return
*/
void b_exit(char **av, int *l_ret)
{
char *line = av[0];
unsigned int ac = 0, bn = 1;/*Boolean to identify if is a number*/
int n_return = 0, i;/*Runner*/
for (; av[ac]; ac++)
;
if (ac >= 2)
{
for (i = 0; (bn == 1) && (av[1][i] != '\0'); i++)
if (av[1][i] < '0' || av[1][i] > '9')
bn = 0;
if (bn == 1)
n_return = _atoi(av[1]);
else
{
*l_ret = 2;
n_return = prt_error(av, 2);/*Pending Handle error*/
}
}
else if (ac == 1)
n_return = *l_ret;
free(av);
free(line);
exit(n_return);
}
/**
* b_env - Print the enviroment variables
* @av: Array of arguments
* @l_ret: Pointer to number of the last return
*/
void b_env(char **av, int *l_ret)
{
unsigned int ac = 0, i;/*Runer*/
for (; av[ac]; ac++)
;
if (ac != 1 || !environ)
*l_ret = 2; /*Pending- handle error*/
else
{
i = 0;
while (environ[i] != NULL)
{
prt_stdo(environ[i]);
prt_stdo("\n");
i++;
}
*l_ret = 0;
}
}