-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv_func.c
45 lines (39 loc) · 858 Bytes
/
env_func.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
#include "simple_shell.h"
/**
*create_env - creates the environmentin a file named env.txt
*@env: enviroment variable
*Return: int status
*/
void create_env(char **env)
{
int fileDesc, envIter = 0, len = 0;
char *home;
home = str_concat(get_home(), "/env.txt");
fileDesc = open(home, O_CREAT | O_WRONLY | O_TRUNC, 0600);
free(home);
if (fileDesc == -1)
return;
while (env[envIter] != NULL)
{
len = _strlen(env[envIter]);
write(fileDesc, env[envIter], len);
write(fileDesc, "\n", 1);
envIter++;
}
close(fileDesc);
}
/**
*_env - prints all the enviromental variables
*@argv: array of strings
*Return: int status
*/
int _env(char *argv[])
{
char *home = str_concat(get_home(), "/env.txt");
char *cat[] = {"/bin/cat", NULL, NULL};
cat[1] = home;
(void) argv;
if (execve(cat[0], cat, NULL) == -1)
exit(-1);
return (0);
}