The getenv function returns a pointer to a string (doc doesn't say null-terminated string)
So, my assumption is that the %str function is useless with getenv
Just this will work too:
getenv('some_var')='some_value';
From documentation:
Return Value
value getenv() successfully found the environment string. The value returned is a pointer to the string containing the value for the specified name in the current environment.
NULL getenv() could not find the environment string. The errno variable is set to indicate the error.
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Justin Taylor
Sent: Thursday, April 23, 2020 13:11
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: %str() use discouraged?
My code works, so maybe my assumption about getenv() returning a null-terminated string was wrong.
-----Original Message-----
From: Francois Lavoie [mailto:Francois.Lavoie@xxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, April 23, 2020 8:34 AM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: %str() use discouraged?
If getenv returns a null-terminated string then the statement should be:
If getenv('ENV_VAR') = %str('Literal value here');
But you would had figured that out
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Justin Taylor
Sent: Thursday, April 23, 2020 09:00
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: %str() use discouraged?
I'm afraid I'm not familiar with a "zero terminated string"
My intended use is this:
If %str(getenv('ENV_VAR')) = 'Literal value here'; Endif;
I believe getenv() returns a null-terminated string.
Thanks
As an Amazon Associate we earn from qualifying purchases.