English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 28 April 2023, 23:12   #1
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Can't set system env variable using C...

Hi,
I am using Bebbo 6.0.5 C compliler.
Can I set system global ENV variable somehow?

I tried:
1. Using SetEnv() but there is no such a function here...
There is only setenv() functino that take only 3 parameters not 4
but it also not working.
Code:
setenv("variable", "value", 1);

2. So I tried to use a system call:
Code:
system("set variable value");
Nothing happens.


3. So I use also
Code:
 Execute("set variable value")
but also nothing.

4. I also foound this piece of code - not working either:
Code:
int setenv(const char *var, const char *value, int overwrite)
{
    struct Process *me = (void *) FindTask(NULL);
    void *old_window = me->pr_WindowPtr;
    int ret = -1;

    me->pr_WindowPtr = (void *) -1;   /* suppress any "Please insert" popups */
    if (SysBase->LibNode.lib_Version >= ReqVers)
        ret = !SetVar((char *)var, (char *)value, -1, GVF_GLOBAL_ONLY | LV_VAR);
    else {
        BPTR hand, foot, spine;
        long len = value ? strlen(value) : 0;
        if (foot = Lock("ENV:", ACCESS_READ)) {
            spine = CurrentDir(foot);
            if (len) {
                if (hand = Open((char *) var, MODE_NEWFILE)) {
                    ret = Write(hand, (char *) value, len + 1) >= len;
                    Close(hand);
                }
            } else
                ret = DeleteFile((char *) var);
            UnLock(CurrentDir(spine));
        }
    }
    me->pr_WindowPtr = old_window;
    return ret;
}
from https://opensource.apple.com/source/...te.c.auto.html
but also not working.

---


EDIT: ---
OK, I used:
Code:
system("setenv variable value");
and now it created it..

Last edited by mateusz_s; 28 April 2023 at 23:24.
mateusz_s is offline  
Old 28 April 2023, 23:18   #2
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,197
can you check with Snoopdos to see what the various programs are doing?


IIRC SetEnv & GetEnv need OS 2.x.
jotd is offline  
Old 28 April 2023, 23:25   #3
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Quote:
Originally Posted by jotd View Post
can you check with Snoopdos to see what the various programs are doing?


IIRC SetEnv & GetEnv need OS 2.x.
I tried
Code:
system("setenv value variable");
instead of
Code:
system("set value variable");
and it worked - it has been saved in env:
mateusz_s is offline  
Old 29 April 2023, 00:13   #4
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
If you are in kickstart >=2, check this
http://amigadev.elowar.com/read/ADCD.../node01BF.html

sample program

Code:
#include <proto/dos.h>

int main(int argc, char **argv) {
  SetVar("testing", "42", -1, GVF_GLOBAL_ONLY);
  return 0;
}
alkis is offline  
Old 29 April 2023, 02:13   #5
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Quote:
Originally Posted by alkis View Post
If you are in kickstart >=2, check this
http://amigadev.elowar.com/read/ADCD.../node01BF.html

sample program

Code:
#include <proto/dos.h>

int main(int argc, char **argv) {
  SetVar("testing", "42", -1, GVF_GLOBAL_ONLY);
  return 0;
}
Yes this should work i tried it - but for some reason
I cant find this function in my Bebbo 6.5.0 C compiler
Instead of SetVar() that takes 4 parameters there is setvar() that takes 3 parametry- but it dont work. I maybe
Try ask Bebbo about it.
mateusz_s is offline  
Old 29 April 2023, 03:15   #6
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by mateusz_s View Post
Yes this should work i tried it - but for some reason
I cant find this function in my Bebbo 6.5.0 C compiler
Instead of SetVar() that takes 4 parameters there is setvar() that takes 3 parametry- but it dont work. I maybe
Try ask Bebbo about it.
What do you mean you can't find this function? Do you get an error from the compiler?

Umm, this is how I compiled it with bebbo's gcc 6.5.0

Code:
m68k-amigaos-gcc -O3 -noixemul -o gvar gvar.c
alkis is offline  
Old 29 April 2023, 17:41   #7
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Quote:
Originally Posted by alkis View Post
What do you mean you can't find this function? Do you get an error from the compiler?

Umm, this is how I compiled it with bebbo's gcc 6.5.0

Code:
m68k-amigaos-gcc -O3 -noixemul -o gvar gvar.c

Hmm.. thats weird. In my case only setvar() tak takes 3 argument is avaiable. The SetVar() isn't. I must check it again.. maybe i missed something.
mateusz_s is offline  
Old 29 April 2023, 19:11   #8
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
do you get any error from the compiler when you try to compile the sample I posted above?
alkis is offline  
Old 29 April 2023, 19:33   #9
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Quote:
Originally Posted by alkis View Post
do you get any error from the compiler when you try to compile the sample I posted above?
Cant check it right now. I will Try a bit later and let know.
mateusz_s is offline  
Old 01 May 2023, 23:27   #10
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Quote:
Originally Posted by alkis View Post
do you get any error from the compiler when you try to compile the sample I posted above?
Yes - its working now.. I dont know what happend -
before my editor (VisualCode) coulnd't find this function -
now its OK - and the compliator/linker finds it too -
and its works in the System.

Thanks For Help
mateusz_s is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get ENV-variables from Arexx? Firestone Coders. Scripting 6 22 August 2022 21:00
using Internet to set system Time utukku support.Apps 11 20 April 2021 03:49
ENV-handler in kickstart Joel_w support.Apps 0 02 August 2019 15:02
Set System Time xArtx Coders. C/C++ 2 04 March 2016 10:24
cannot save files to env: amifreak support.Hardware 2 20 December 2004 02:01

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:06.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10976 seconds with 13 queries