forked from svilladaniel/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilt-in.c
More file actions
72 lines (70 loc) · 1.25 KB
/
built-in.c
File metadata and controls
72 lines (70 loc) · 1.25 KB
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
65
66
67
68
69
70
71
72
#include "holberton.h"
/**
* _myexit - check command line to exit shell
* @line: command line
* Return: 0 (Success) 1 (Fail)
**/
int _myexit(char *line)
{
char *exit_line = "exit";
int i = 0;
int len = _strlen(line);
if (len == 4)
{
while (exit_line[i])
{
if (exit_line[i] != line[i])
return (1);
i++;
}
free(line);
return (0);
}
return (1);
}
/**
* signal_c - Ignore input signal Ctrl + C
* @sign: siganal parameter
**/
void signal_c(int sign)
{
signal(sign, SIG_IGN);
write(STDOUT_FILENO, "\n#cisfun$ ", 11);
signal(SIGINT, signal_c);
}
/**
* _myenv - print the environment variables separated.
* @line: The command line.
* @counter: number of entry arguments
* @argv: entry arguments from main
* @env: enviroment variables
* Return: 0 if succes or 1 if fails. 127 if env not found
**/
int _myenv(char *line, int counter, char **argv, char **env)
{
char *env_line = "env";
int i = 0;
int len = _strlen(line);
if (len == 3)
{
while (env_line[i])
{
if (env_line[i] != line[i])
return (1);
i++;
}
if (env)
{
for (i = 0; env[i] != NULL; i++)
_printf("%s\n", env[i]);
free(line);
return (0);
}
else
{
_printf("%s: %d: env: not found\n", argv[0], counter);
return (127);
}
}
return (1);
}