forked from Wa2hingt0n/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilt-in.c
81 lines (74 loc) · 1.42 KB
/
built-in.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "shell.h"
/**
* _cd - function to implement change directory
* @args: command arguements
*
* Return: 1 on success
*/
int _cd(char **args)
{
if (args[1] == NULL)
{
write(2, "lsh: expected argument to \"cd\"\n", 31);
}
else
{
if (chdir(args[1]) != 0)
{
perror("lsh");
}
}
/*free(args);*/
return (1);
}
/**
* _help - to display shell usage
* now it is hard coded, but as we progress, we will be reading
* from a file
* @args: command to be executed
*
* Return: Int
*/
int _help(__attribute__((unused)) char **args)
{
write(1, "Joseph & Washington shell\n", 26);
write(1, "Type program names and arguments, and hit enter.\n", 49);
write(1, "The following are built in:\n", 28);
write(1, "* cd\n", 5);
write(1, "* help\n", 7);
write(1, "* exit\n", 7);
write(1, "\nUse the man command for information on other programs.\n", 57);
/*free(args);*/
return (1);
}
/**
* _exitprog - The function that would exit the program
* @args: The command entered
*
* Return: 0 on success
*/
int _exitprog(char **args)
{
free(args);
exit(0);
return (0);
}
/**
* print_env - Prints the current environment
* @argv: Command "env"
*
* Return: Nothing
*/
int print_env(__attribute__((unused)) char **argv)
{
/*extern char **environ;*/
int i = 0;
while (environ[i] != NULL)
{
write(STDOUT_FILENO, environ[i], _strlen(environ[i]));
write(STDOUT_FILENO, "\n", 1);
i++;
}
/*free(argv);*/
return (0);
}