-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildin.c
47 lines (43 loc) · 844 Bytes
/
buildin.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
#include "shell.h"
/**
* my_exit - simple impl of exit.
* @ptrs: structure containing all malloced memory
*/
void my_exit(shell_t *ptrs)
{
unsigned int i;
char *exit_str;
exit_str = ptrs->input_token[1];
if (exit_str != NULL || ptrs == NULL)
{
errno = 0;
for (i = 0; exit_str[i] != '\0'; i++)
errno = errno * 10 + (exit_str[i] - '0');
}
free_shell_t(ptrs);
if (errno > 255)
errno %= 256;
exit(errno);
}
/**
* print_env - prints out the current environment
* @ptrs: structure containing all malloced memory
*/
void print_env(shell_t *ptrs)
{
unsigned int i, k;
char newline = '\n';
(void)ptrs;
if (environ == NULL)
return;
for (i = 0; environ[i] != NULL; i++)
{
k = _strlen(environ[i]);
if (k != 0)
{
write(STDOUT_FILENO, environ[i], k);
write(STDOUT_FILENO, &newline, 1);
}
}
errno = 0;
}