How to create an environment variable in BSP startup file ?

Hi everybody !

I want to create an environment variable in startup in order to retrieve it in a QNX program.
Startup will read the value in a EEPROM, store it in an environment variable and so my QNX program will retrieve it.

I saw that function add_typed_string can set predefined variable but I want to create a new one. The function add_string could be OK but how my QNX program can retrieve the index returned ?

Thanks for your help !


Assuming you can read the EEPROM value at startup, how are you going to set the environment variable. Via a shell script or a C program?

From a shell script (or from the command prompt for testing) you can do the following:

export name=value

So for example you can do

export Metais=100

Then to see the value of Metais from a script/command prompt do

echo $Metais

which will then show 100.

To get the value of Metais from a C program you have the following code:

char *tmp = getenv(“Metais”);

This will load ‘100’ into the tmp string which you can then parse to get the value your looking for.

Note: You can use setenv() to set an environment variable from a C program if that’s what your using to read the EEPROM at start time.



Some terminology here. What you want to do is create a syspage entry (not an environment variable).

Creating a new property in the syspage is not difficult.

In order to oass some data from your startup to your application in a non-portable way, the easiest thing to do would be to use add_string() (rather than add_typed_string). Defining a string in the format of an environment variable make sense.

For example to add a property FOO with a value BAR:

(in the startup)


To retrieve the property FOO at process time (QNX running)

char *p=SYSPAGE_ENTRY(strings)->data;

while(*p) {
   if(strncmp(p, "FOO", 3) == 0) {
     char buf[80];
     char *p1,*p2;

     // found property FOO, now copy string and strtok() on '=' to get value
     strcpy(buf, p);
     p1=strtok(buf, "=");
     p2=strtok(NULL, "");
     // p2 is equal to FOO value (in this case "BAR")    
   p += strlen(p);

Since this is non-portable, you should be sure that the property is not something that maps into the CS stuff…


BSP startup is written in C and setenv() function is not working at this moment.


Your solution is working fine ! (the line p += strlen(p); should be p += (strlen(p)+1); because strings are zero terminated). I observed that size or syspage is 32768 bytes and that use bigger size then QNX is not started ! it doesn’t matter, I just need few bytes to transmit value.

Thanks you two for your answers.

It was typed on the fly as an illustrative fragment (I am surprised that was the only bug !).

Glad you got it working!