forked from gstieg/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpfunc2.c
112 lines (99 loc) · 1.6 KB
/
helpfunc2.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "shell.h"
/**
* _strdup - _strdup dupliacte function
*
* @org: input for org
*
* Return: dup
*/
char *_strdup(char *org)
{
int org_size;
static char *dup;
char *dup_offset;
org_size = _strlen(org);
dup = (char *)malloc(sizeof(char) * org_size + 1);
if (dup == NULL)
return ((char *)NULL);
dup_offset = dup;
while (*org)
{
*dup_offset = *org;
dup_offset++;
org++;
}
{
if (org == NULL)
return (0);
}
*dup_offset = '\0';
return (dup);
}
/**
* _strcat - cat the string
*
* @destination: input for _strcat
*
* @source: input for the source
*
* @num: input for num
*
* Return: destination
*/
char *_strcat(char *destination, const char *source, size_t num)
{
char *ptr = destination + _strlen(destination);
while (*source != '\0' && num--)
*ptr++ = *source++;
*ptr = '\0';
return (destination);
}
/**
*printenv- function to print env
*
*Return: void
*/
void printenv(void)
{
int i;
size_t sl;
i = 0;
while (environ[i] != NULL)
{
sl = _strlen(environ[i]);
write(STDOUT_FILENO, environ[i], (sl + 1));
write(STDOUT_FILENO, "\n", 1);
i++;
}
}
/**
* pathString - pathString func
*
* Return: pathString
*/
char *pathString(void)
{
int i = 0, j = 0;
char **getPath, **ev;
char *path = "PATH";
ev = malloc(sizeof(char *) * 100);
while (environ[j] != NULL)
{
ev[j] = _strdup(environ[j]);
j++;
}
getPath = _parseline(ev[i], "=");
while (ev[i] != NULL)
{
getPath = _parseline(ev[i], "=");
getPath = _parseline(NULL, ev[i]);
if (_strcmp(getPath[i], path) == 0)
{
free(ev);
return (environ[i]);
}
i++;
}
free(ev);
return (0);
}