Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where is the definition of extern char **environ?

Tags:

c

linux

we can get the environment variable in C like this:

extern char **environ;
int main(int argc, char *argv[])
{
    int count = 0;

    printf("\n");
    while(environ[count] != NULL)
   {
         printf("[%s] :: ", environ[count]);
         count++;
   }

   return 0;
}

but where is the defination of environ? I can't find that in unistd.h. and how does it work?

like image 911
nzomkxia Avatar asked May 18 '12 08:05

nzomkxia


People also ask

What is extern char environ?

extern char **environ; environ is a pointer to a NULL-terminated array of pointers to null-terminated character strings. Each string has the form "name=value" to indicate the name of an environment variable and its current value.

Where is Environ defined?

environ is defined as a global variable in the Glibc source file posix/environ.

What is environ in C?

The variable environ points to an array of pointers to strings called the "environment". The last pointer in this array has the value NULL. This array of strings is made available to the process by the execve(2) call when a new program is started.


1 Answers

environ is defined as a global variable in the Glibc source file posix/environ.c.

like image 83
Fred Foo Avatar answered Oct 14 '22 07:10

Fred Foo