Back to index

tetex-bin  3.0
Defines | Functions | Variables
putenv.c File Reference

Go to the source code of this file.

Defines

#define NULL   0
#define PSIZE   sizeof(char *)

Functions

char * strchr ()
char * malloc ()
int putenv (char *entry)

Variables

char ** environ

Define Documentation

#define NULL   0

Definition at line 27 of file putenv.c.

#define PSIZE   sizeof(char *)

Definition at line 28 of file putenv.c.


Function Documentation

char* malloc ( )
int putenv ( char *  entry)

Definition at line 65 of file putenv.c.

{
  unsigned length;
  unsigned size;
  char     *temp;
  char     **p;
  char     **new_environ;

  /*  Find the length of the "NAME="  */

  temp = strchr(entry,'=');
  if ( temp == 0 )
    return( -1 );

  length = (unsigned) (temp - entry + 1);


  /*  Scan through the environment looking for "NAME="  */

  for ( p=environ; *p != 0 ; p++ )
    if ( strncmp( entry, *p, length ) == 0 )
      {
      *p = entry;
      return( 0 );
      }


  /*  The name was not found, build a bigger environment  */

  size = p - environ;

  new_environ = (char **) malloc( (size+2)*PSIZE );

  if ( new_environ == (char **) NULL )
    return( -1 );

  memcpy ((char *) new_environ, (char *) environ, size*PSIZE );

  new_environ[size]   = entry;
  new_environ[size+1] = NULL;

  environ = new_environ;

  return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* strchr ( )

Variable Documentation

char** environ