Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
91 user(s) are online (60 user(s) are browsing Forums)

Members: 1
Guests: 90

sailor, more...

Headlines

 
  Register To Post  

Is setenv() works with newlib ?
Home away from home
Home away from home


See User information
Tried some simple test case :

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

int main()
{
setenv("TEST_ENV","0"1);
}


Then spawn a shell, compile, run, and in the same shell trying to "getenv TEST_ENV" return me object not found. I.e. environment wasn't set.

Is it expected with newlib to be like this, like its not out setenv, but just some local setenv in unix style ?

Is there some os4 native mechanism to set environment globally from C code ? I of course can just do something like IDOS->System("setenv TEST_ENV 0", NULL); , but not sure if it right thing to do like this.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: Is setenv() works with newlib ?
Home away from home
Home away from home


See User information
@kas1e

setenv() set a local variable (visible with getenv()) which will be inherited by all sub processes, it does not set the global ENV: variables or even the local shel variables. THis might not be obvious as the intial set of variables *is* imported from the Amiga environment.

To access / modify the amiga envoronment use IDOS->GetVar(), IDOS->SetVar(), etc.

Go to top
Re: Is setenv() works with newlib ?
Just can't stay away
Just can't stay away


See User information
@kas1e

Quote:
I of course can just do something like IDOS->System("setenv TEST_ENV 0", NULL); , but not sure if it right thing to do like this.

No it's not. Look at SetVar() in the DOS autodocs.

The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
Go to top
Re: Is setenv() works with newlib ?
Home away from home
Home away from home


See User information
@Andy,Dan
Yeah, SetVar is what i need indeed, thanks!

EDIT: should it works for the current process from which is set ?

I.e. i have a game, for which i need special environment set, so i do set it right at begining of main(), but it seems it didn't take action for that binary, while in system it all looks like environment was set.

I.e. i just do it like this:

IDOS->SetVar("MYENV", "40", 2, GVF_GLOBAL_ONLY);

And while when i do in another shell "getenv MYENV" while game is running, i have correct "40" in otuput, but it seems that it didn't taken in action for the binary from which i run it.

Just in case i tried and GVF_LOCAL_ONLY mode too, same result..

EDIT2:

Same if i just tried "IDOS->System("setenv LIBGL_BATCH 0-40", NULL);" , it also didn't takes in action when i run it from begining of main() before actual code which want to check on that environment (but when i run second time, it then take it).

Test cases works fine through, but inside of game it is not. Strange ! Like it use code which is check variable way before main()

EDIT3:

Oh sorry for spam , found why it didn't works : check on that environment was indeed in constructor, so before main().


Edited by kas1e on 2019/10/17 15:47:32
Edited by kas1e on 2019/10/17 15:51:47
Edited by kas1e on 2019/10/17 18:11:36
Edited by kas1e on 2019/10/17 18:19:50
Edited by kas1e on 2019/10/17 18:53:33
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: Is setenv() works with newlib ?
Home away from home
Home away from home


See User information
@kas1e

I'm not sure that setting env vars from the main executable of program is a good idea, they are presumably for allowing the user to choose options, if you need those options permanently set then perhaps it would be better to override the code that checkc the env var.

If you still need them as options , then wrap the main executable in a script ( in the same way as 'blender' is ascript wrapping 'bldyn' or timberwolf etc).


Go to top
Re: Is setenv() works with newlib ?
Home away from home
Home away from home


See User information
@broadblues
In my case that environemtn should be set 100%, or instead you will have visuall issues. I.e. that shouldn't be controlled by user. On running i do getvar() to grab current value (if there any), then set my one, and on exit restore original one. I also do set it localy for process now, so all should be fine

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project