-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_built.c
More file actions
95 lines (87 loc) · 1.58 KB
/
_built.c
File metadata and controls
95 lines (87 loc) · 1.58 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "holberton.h"
/**
* _buitins - validates if command is builtin and executes
* @ssh: input ssh
* Return: true if found, false if not
*/
_Bool _builtins(_unix *ssh)
{
register int i = 0;
cmd Builtins[] = {
{"exit", _exitsv},
{"env", _enviroment},
{"history", _hFunc},
{"alias", _alias},
{"cd", _cd},
{"setenv", setenvFunc},
{"unsetenv", unsetenvFunc},
{"help", helpFunc},
{NULL, NULL}
};
while (Builtins[i].command)
{
if (_strcmp(ssh->args[0], Builtins[i].command) == 0)
{
Builtins[i].func(ssh);
freeBuffer(ssh);
return (true);
}
i++;
}
return (false);
}
/**
* _exitsv - exits the application
* @ssh: input ssh
* Return: 1 on success, 0 on failure
*/
int _exitsv(_unix *ssh)
{
register int argc, exitstatus;
argc = Arguments(ssh->args);
if (argc == 1)
{
freeData(ssh);
if (ssh->errorStatus)
exit(ssh->errorStatus);
exit(EXIT_SUCCESS);
}
else if (argc > 1)
{
exitstatus = _atoi(ssh->args[1]);
if (exitstatus == -1)
{
errno = RALLOC;
ssh->errorStatus = 2;
_getError(ssh);
return (0);
}
freeData(ssh);
exit(exitstatus);
}
return (1);
}
/**
* _hFunc - displays command history
* @ssh: input ssh
* Return: 1 on success, 0 on failure
*/
int _hFunc(_unix *ssh)
{
char *str = "Currently in development\n";
(void)ssh;
write(STDOUT_FILENO, str, _strlen(str));
return (1);
}
/**
* _alias - displays local aliases
* @ssh: input ssh
* Return: 1 on success, 0 on failure
*/
int _alias(_unix *ssh)
{
char *str = "Currently in development\n";
(void)ssh;
write(STDOUT_FILENO, str, _strlen(str));
return (1);
}