clearenv()

Clear the environment

Synopsis:

#include <stdlib.h>

int clearenv( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The clearenv() function clears the environment area; no environment variables are defined immediately after the clearenv() call.

Note that clearenv() clears the following environment variables, which may then affect the operation of other library functions such as spawnp() :

  • PATH
  • SHELL
  • TERM
  • TERMINFO
  • LINES
  • COLUMNS
  • TZ

Returns:

0
Success.
-1
An error occurred ( errno is set).

Errors:

ENOMEM
Not enough memory to allocate a control structure.

Examples:

Clear the entire environment and set up a new TZ environment variable:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    if( clearenv() != 0 ) {
        puts( "Unable to clear the environment" );
        return EXIT_FAILURE;
    }

    setenv( "TZ", "EST5EDT", 0 );
    
    return EXIT_SUCCESS;
}

Classification:

QNX 4

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

The clearenv() function manipulates the environment pointed to by the global environ variable.

Last modified: 2013-12-23

comments powered by Disqus