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():

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 Neutrino

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.