-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.c
64 lines (60 loc) · 1004 Bytes
/
helpers.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
#include "shell.h"
/**
*_memset - set the memory with a constant byte
*@s: array to fill
*@c: character to fill with
*@bytes: number of bytes to fill
*Return: new array
*/
char *_memset(char *s, char c, unsigned int bytes)
{
unsigned int i;
for (i = 0; i < bytes; i++)
s[i] = c;
return (s);
}
/**
*_getenv - get the PATH
*@member: PATH string
*Return: pointer to member if found
*/
char *_getenv(const char *member)
{
int i, r;
for (i = 0; environ[i]; i++)
{
r = _strcmp_path(member, environ[i]);
if (r == 0)
return (environ[i]);
}
return (NULL);
}
/**
*_strcmp - compare 2 strings
*@s1: first string
*@s2: second string
*Return: integer
*/
int _strcmp(char *s1, char *s2)
{
int i = 0;
while ((s1[i] != '\0' && s2[i] != '\0') && s1[i] == s2[i])
{
i++;
}
if (s1[i] == s2[i])
return (0);
else
return (s1[i] - s2[i]);
}
/**
*_environ - print the environ
*Return: 0 on success
*/
int _environ(void)
{
int i;
for (i = 0; environ[i]; i++)
_puts(environ[i]);
return (0);
}