-
Notifications
You must be signed in to change notification settings - Fork 1
/
built_commands.c
61 lines (58 loc) · 1.07 KB
/
built_commands.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
#include "holberton.h"
/**
* enviroment - print the enviroment variables
* @env: enviroment variables
*
* Description: print the enviroment variables in simple shell
*
* Return: void
*/
void enviroment(char **env)
{
int env_i = 0;
while (env[env_i] != NULL)
{
write(STDOUT_FILENO, env[env_i], _strlen(env[env_i]));
write(STDOUT_FILENO, "\n", 1);
env_i++;
}
}
/**
* built_commands - Function that compare and execute built-in commands
*
* @args: Pointer to pointer type char
* @buffer: Pointer type char
* @env: Pointer to pointer type char
*
* Return: int
*/
int built_commands(char **args, char *buffer, char **env)
{
if ((_strcmp(args[0], "exit")) == 0)
{
free(buffer);
free(args);
exit(0);
return (1);
}
else if ((_strcmp(args[0], "env")) == 0)
{
enviroment(env);
free(buffer);
free(args);
return (1);
}
return (0);
}
/**
* handle_sigint - take signal from stdin
* @sig: signal value
*
* Description: take a signal from stdin and prints it
* Return: void
*/
void handle_sigint(int sig)
{
(void)sig;
write(STDOUT_FILENO, "\n$ ", 3);
}