-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_function.c
More file actions
50 lines (47 loc) · 1.03 KB
/
Copy pathfind_function.c
File metadata and controls
50 lines (47 loc) · 1.03 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
#include "main.h"
/**
* find_function - Find and execute a built-in function
* @token: The command token to check
* @original: The original command string
*
* Return: 0 if a built-in function is executed, 1 otherwise
*/
int find_function(char *token, char *original)
{
char sep[] = "\n ";
if (_strcmp(token, "cd") == 0)
{
_chdir(original);
return (0);
}
else if (_strcmp(token, "exit") == 0)
{
token = _strtok(NULL, sep);
if (token == NULL)
{
kill(getppid(), SIGINT);
kill(getpid(), SIGINT);
}
else
{
exit(atoi(token));
}
return (0);
}
else if (_strcmp(token, "env") == 0)
{
_printenv();
return (0);
}
else if (_strcmp(token, "setenv") == 0)
{
_setenv(_strtok(NULL, sep), _strtok(NULL, sep), 1);
return (0);
}
else if (_strcmp(token, "unsetenv") == 0)
{
_unsetenv(_strtok(NULL, sep));
return (0);
}
return (1);
}