putenv example in C

Use : To change the environmental variable value

Syntax: int putenv(char *string)

Arguments : Takes a string as NAME=VALUE, where NAME  is the name of the environmental variable and VALUE is the value of the environmental variable you want to set

If NAME is present in the environment list then replace the value else it will add this to the environmental list

Return Type: 0 on success
                      -1  if any error


Code:


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

int main()
{
int result=putenv("NAME=TEST");

if(result==0)
{
printf("\n environmental variable successfully written");
printf("\n value of the environmental variable written is %s",getenv("NAME"));

}else{
printf("\n error in writing the environmental variable");
}


return 0;
}

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto