A
Anonymous
[Whether your post is on-topic for comp.lang.c is purely a
matter of opinion, since nobody has any authority to impose
an ANSI/ISO C topicality restriction on this newsgroup. If
you want more people available for replies, simply cross-post
to comp.lang.c *and* comp.unix.programmer.]
The two common ways of accessing the environment directly on
many Unix and Unix-like systems are as follows:
(1) Through a third argument to the main() function, typically
called 'envp' and used in a manner analogous to 'argv'.
(2) Through the global 'environ' variable, which is a
char **.
I have some idea of what you're trying to do. What may help you is
that execle() and execve() let you control the environment of the
program you're executing. So instead of using setenv() or putenv()
in the calling program or screwing around with the shell, you can do
something like
char *my_env[] = {"MYVAR=mydata", NULL};
and pass that as the final argument to execle() or execve().
That may be one way of helping you with consistency, and you can
also use a consistent argv[0] length in those exec* calls.
However, there are various factors (including kernel modifications)
on modern systems that may make getting a consistent location across
program executions extremely difficult. Also, if you're trying to
execute assembly code stashed in the environment, this may not even
be allowed on some of these systems.
My advice is to make sure you're reading from material that is no
more than 5 years old.
Yours,
Han from China
matter of opinion, since nobody has any authority to impose
an ANSI/ISO C topicality restriction on this newsgroup. If
you want more people available for replies, simply cross-post
to comp.lang.c *and* comp.unix.programmer.]
The two common ways of accessing the environment directly on
many Unix and Unix-like systems are as follows:
(1) Through a third argument to the main() function, typically
called 'envp' and used in a manner analogous to 'argv'.
(2) Through the global 'environ' variable, which is a
char **.
I need these infos cuz i need to put datas in the stack to be easily
picked up by the program itself, without using getenv, only with an
address.
I have some idea of what you're trying to do. What may help you is
that execle() and execve() let you control the environment of the
program you're executing. So instead of using setenv() or putenv()
in the calling program or screwing around with the shell, you can do
something like
char *my_env[] = {"MYVAR=mydata", NULL};
and pass that as the final argument to execle() or execve().
That may be one way of helping you with consistency, and you can
also use a consistent argv[0] length in those exec* calls.
However, there are various factors (including kernel modifications)
on modern systems that may make getting a consistent location across
program executions extremely difficult. Also, if you're trying to
execute assembly code stashed in the environment, this may not even
be allowed on some of these systems.
My advice is to make sure you're reading from material that is no
more than 5 years old.
Yours,
Han from China