-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltins2.c
54 lines (50 loc) · 1.04 KB
/
builtins2.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
#include "shell.h"
/**
* sh_setenv - sets enviroment variables
* @args: arguments provided Variable and Value
*
* Return: 0 if successful, or 1 if not
*/
int sh_setenv(char **args)
{
int status;
if (args[1] == NULL || args[2] == NULL)
{
printf("setenv: provide proper arguments (setenv VARIABLE VALUE)\n");
return (1);
}
status = setenv(args[1], args[2], 1);
if (status != 0)
{
printf("setenv: Error while setting enviroment variable\n");
return (1);
}
return (0);
}
/**
* sh_unsetenv - unsets/removes enviroment variables
* @args: arguments provided Variable(to be removed)
*
* Return: 0 if successful, or 1 if not
*/
int sh_unsetenv(char **args)
{
int status;
if (args[1] == NULL)
{
printf("unsetenv: provide proper arguments (unsetenv VARIABLE)\n");
return (1);
}
if (getenv(args[1]) == NULL)
{
printf("unsetenv: No such environment variable\n");
return (1);
}
status = unsetenv(args[1]);
if (status != 0)
{
printf("unsetenv: Error while unsetting enviroment variable\n");
return (1);
}
return (0);
}