-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSS_builtin.c
More file actions
92 lines (85 loc) · 1.9 KB
/
SS_builtin.c
File metadata and controls
92 lines (85 loc) · 1.9 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
#include "shell.h"
/**
* _myexit - This function is responsible for handling the exit command
* @info: Function parameter that indicates the struct containing potential arg
* Return: 0 if successful.
*/
int _myexit(info_t *info)
{
int exit_check;
if (info->argv[1])
{
exit_check = _erratoi(info->argv[1]);
if (exit_check == -1)
{
info->status = 2;
_eputs(info->argv[1]);
print_error(info, "number not allowed: ");
_eputchar('\n');
return (1);
}
info->err_num = _erratoi(info->argv[1]);
return (-2);
}
info->err_num = -1;
return (-2);
}
/**
* _mycd - This function handles the change directory command in the shell.
* @info: Function parameter indicating the struct containing potential args.
* Return: 0 if successful.
*/
int _mycd(info_t *info)
{
char *dir;
char buffer[1024];
char *s = getcwd(buffer, 1024);
int chdir_ret;
if (!s)
_puts("TODO: >>getcwd failure emsg here<<\n");
if (!info->argv[1])
{
dir = _getenv(info, "HOME=");
if (!dir)
chdir_ret = chdir((dir = _getenv(info, "PWD=")) ? dir : "/");
else
chdir_ret = chdir(dir);
}
else if (_strcmp(info->argv[1], "-") == 0)
{
if (!_getenv(info, "OLDPWD="))
{
_puts(s);
_putchar('\n');
return (1);
}
_puts(_getenv(info, "OLDPWD=")), _putchar('\n');
chdir_ret = chdir((dir = _getenv(info, "OLDPWD=")) ? dir : "/");
}
else
chdir_ret = chdir(info->argv[1]);
if (chdir_ret == -1)
{
print_error(info, "cannot cd to ");
_eputs(info->argv[1]), _eputchar('\n');
}
else
{
setenv("OLDPWD", _getenv(info, "PWD="), 1);
setenv("PWD", getcwd(buffer, 1024), 1);
}
return (0);
}
/**
* _myhelp - This function handles the help command in the shell.
* @info: Parameter containing potential arguments.
* Return: 0 if successful.
*/
int _myhelp(info_t *info)
{
char **arg_array = info->argv;
_puts("help call works. Function not yet implemented\n");
if (0)
_puts(*arg_array);
return (0);
}