-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinborns.c
65 lines (61 loc) · 1.13 KB
/
inborns.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
65
#include "shell.h"
/**
* findinborns - validates if command is builtin and executes
* @build: input build
* Return: true if found, false if not
*/
bool findinborns(vars_t *build)
{
register int i = 0;
inborns_t getinborns[] = {
{"exit", exitFunc},
{"env", envFunc},
{"cd", cdFunc},
{"setenv", setenvFunc},
{"unsetenv", unsetenvFunc},
{"help", helpFunc},
{NULL, NULL}
};
while (getinborns[i].cmd)
{
if (_strcmp(build->args[0], getinborns[i].cmd) == 0)
{
getinborns[i].func(build);
freeArgsAndBuffer(build);
return (true);
}
i++;
}
return (false);
}
/**
* exitFunc - exits the application
* @build: input build
* Return: 1 on success, 0 on failure
*/
int exitFunc(vars_t *build)
{
register int argCount, exitStatus;
argCount = countArgs(build->args);
if (argCount == 1)
{
freeMembers(build);
if (build->error)
exit(build->error);
exit(EXIT_SUCCESS);
}
else if (argCount > 1)
{
exitStatus = _atoi(build->args[1]);
if (exitStatus == -1)
{
errno = EILLEGAL;
build->error = 2;
errorHandler(build);
return (0);
}
freeMembers(build);
exit(exitStatus);
}
return (1);
}