-
Notifications
You must be signed in to change notification settings - Fork 3
/
builtin1.c
97 lines (91 loc) · 2.01 KB
/
builtin1.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "shell.h"
/**
* _myexit - exits
* @info: Structure that has possib;e arguments. Used to maintain
* constant function prototype.
* Return: exits with exit status
* (0) when info.argv[0] != "exit"
*/
int _myexit(info_t *info)
{
int exitcheck;
if (info->argv[1]) /* If an exit arguement exists*/
{
exitcheck = _erratoi(info->argv[1]);
if (exitcheck == -1)
{
info->status = 2;
print_error(info, "Illegal number: ");
_eputs(info->argv[1]);
_eputchar('\n');
return (1);
}
info->err_num = _erratoi(info->argv[1]);
return (-2);
}
info->err_num = -1;
return (-2);
}
/**
* _mycd - changes current directory in shell
* @info: Structure that has pssible arguments. Used to maintain
* constant function prototype.
* Return: Always 0
*/
int _mycd(info_t *info)
{
char *z, *dr, buffer[1024];
int chdir_ret;
z = getcwd(buffer, 1024);
if (!z)
_puts("TODO: >>getcwd failure msg here<<\n");
if (!info->argv[1])
{
dr = _getenv(info, "HOME=");
if (!dr)
chdir_ret = /* TODO: what should it be? */
chdir((dr = _getenv(info, "PWD=")) ? dr : "/");
else
chdir_ret = chdir(dr);
}
else if (_strcmp(info->argv[1], "-") == 0)
{
if (!_getenv(info, "OLDPWD="))
{
_puts(z);
_putchar('\n');
return (1);
}
_puts(_getenv(info, "OLDPWD=")), _putchar('\n');
chdir_ret = /* TODO: what should it be? */
chdir((dr = _getenv(info, "OLDPWD=")) ? dr : "/");
}
else
chdir_ret = chdir(info->argv[1]);
if (chdir_ret == -1)
{
print_error(info, "can't cd to ");
_eputs(info->argv[1]), _eputchar('\n');
}
else
{
_setenv(info, "OLDPWD", _getenv(info, "PWD="));
_setenv(info, "PWD", getcwd(buffer, 1024));
}
return (0);
}
/**
* _myhelp - changes cirrent directory
* @info: Structure tht has potential arguments.maintains
* constant function prototype.
* Return: Always 0
*/
int _myhelp(info_t *info)
{
char **arg_arr;
arg_arr = info->argv;
_puts(" Function not yet implemented \n");
if (0)
_puts(*arg_arr); /* Temp att_unused */
return (0);
}