ENV VAR addresses


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 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
 
Ad

Advertisements

J

Joachim Schmitz

Anonymous said:
[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 **.

(3) use getenv()

By, Jojo
 
Ad

Advertisements

K

Kenny McCormack

Piggy-backing on Joachim Schmitz's reply to one of the trolls in my
killfile::
Anonymous said:
[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.]

Note that the above is completely illogical.
There may be no one who can enforce topicality, but the fact is that
there are known standards for topicality, These have some fuzziness at
the edges, but most posts are clearly topical or clearly not-topical.
One does not need an enforcer to know this; to suggest that one does
need such an enforcer or else there are no norms suggests that
"Anonymous" is an extremely sick person with no place in any society.

PKB (at best)

The reality is that you're not qualified to shine Mr. Twink's shoes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top