summaryrefslogtreecommitdiff
path: root/libc/stdlib/getenv.c
blob: 1ed83a622f4af2103a3486af245edd1b74fb46f5 (plain)
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
/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
 * This file is part of the Linux-8086 C library and is distributed
 * under the GNU Library General Public License.
 */
#include <string.h>
#include <stdlib.h>
#include <malloc.h>

extern char ** environ;

char *
getenv(var)
const char * var;
{
   char **p;
   int len;

   len = strlen(var);
   
   if (!environ)
      return 0;

   for(p=environ; *p; p++)
   {
      if( memcmp(var, *p, len) == 0 && (*p)[len] == '=' )
         return *p + len + 1;
   }
   return 0;
}