-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_getenv.c
More file actions
26 lines (25 loc) · 783 Bytes
/
Copy path_getenv.c
File metadata and controls
26 lines (25 loc) · 783 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
#include "main.h"
/**
* _getenv - gets an environment variable without using getenv
* @name: environment variable name
* Return: returns the address of the environmnet variable
*/
char *_getenv(const char *name)
{
/*variable to return found env. varaible value*/
char *var_isFound = NULL;
/*STORE ENVIRON IN A POINTER VARIABLE */
char **search_env = environ;
/*LOOP THROUGH THE GLOBAL ENV. VARIABLE*/
for (; *search_env; search_env++)
{
/*COMPARE THE NAME OF var we looking for wt, global environ*/
if (strncmp(name, *search_env, strlen(name)) == 0)
{
/*mv ptr pass the name & equalto of key to the val*/
var_isFound = *search_env + strlen(name) + 1;/*1 byte for NULL TERM*/
return (var_isFound);
}
}
return (NULL);/*if nothing is eventually found*/
}