-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetpath.c
More file actions
47 lines (41 loc) · 841 Bytes
/
Copy pathgetpath.c
File metadata and controls
47 lines (41 loc) · 841 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
#include "main.h"
/**
* _strncmp - Compares two strings
* @str1: First string parameter
* @str2: Second string parameter
* @n: Number of characters to compare
* Return: Integer
*/
int _strncmp(const char *str1, const char *str2, int n)
{
while (n > 0 && *str1 && (*str1 == *str2))
{
str1++;
str2++;
n--;
}
if (n == 0)
return (0);
return (*(unsigned char *)str1 - *(unsigned char *)str2);
}
/**
* getpath - get the path environment variable
* @env: environment variables
* Return: path variable if found
*/
char *getpath(char **env)
{
char *path_variable = NULL;
int i;
if (env == NULL)
return (NULL);
for (i = 0; env[i] != NULL; i++)
{
if (_strncmp(env[i], "PATH=", 5) == 0)
{
path_variable = env[i] + 5;
return (path_variable);
}
}
return (NULL);
}