-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_command.c
More file actions
52 lines (41 loc) · 891 Bytes
/
Copy pathget_command.c
File metadata and controls
52 lines (41 loc) · 891 Bytes
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
#include "shell.h"
/**
* _getspath - get variable PATH.
* @env: enviromente local
* Return: value of PATH.
*/
char *_getspath(char **env)
{
size_t ex = 0, ar = 0, count = 5;
char *path = NULL;
for (ex = 0; _strncmp(env[ex], "PATH=", 5); ex++)
;
if (env[ex] == NULL)
return (NULL);
for (count = 5; env[ex][ar]; ar++, count++)
;
path = malloc(sizeof(char) * (count + 1));
if (path == NULL)
return (NULL);
for (ar = 5, count = 0; env[ex][ar]; ar++, count++)
path[count] = env[ex][ar];
path[count] = '\0';
return (path);
}
/**
* _getuser_command - get command from user.
* Return: line of str entered by user.
*/
char *_getuser_command(void)
{
char *lineptre = NULL;
size_t _user = 0;
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "$: ", 3);
if (getline(&lineptre, &_user, stdin) == -1)
{
free(lineptre);
return (NULL);
}
return (lineptre);
}