Skip to content

Instantly share code, notes, and snippets.

@davixcky
Last active April 11, 2020 04:04
Show Gist options
  • Save davixcky/01dcc2391d5b3e59f9de9b5b1ee74b5f to your computer and use it in GitHub Desktop.
Save davixcky/01dcc2391d5b3e59f9de9b5b1ee74b5f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int _strlen(const char *str)
{
int i;
for (i = 0; str[i] != 0; i++)
;
return (i);
}
char *_getenv(const char *name)
{
extern char **environ;
char **env;
char *aux, *token;
int size, size_aux;
int i;
size = _strlen(name);
env = environ;
for (; *env; ++env)
{
aux = *env;
size_aux = _strlen(aux);
token = strtok(aux, "=");
if (token == NULL)
return (NULL);
if (_strlen(token) != size)
continue;
for (i = 0; i < size; i++)
{
if (name[i] != aux[i])
break;
else if (name[i] == aux[i] && i == size - 1)
return (strtok(NULL, "="));
}
}
return (NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment