Daniel ha scritto:
Das funktioniert einwandfrei. Dankeschön :)
Grüße, Daniel
Am 15.12.05 schrieb Hannes Mayr bik@bauchlandung.org:
Daniel wrote:
Ich meine den Benutzer der das Program ausführt und bräuchte es in C (wenn das überhaupt geht). In der Shell würde der Befehl "printenv HOME"; jedoch gibt printenv nicht den String (also das Home Verzeichnes) sondern den Befehlstatus zurück.
char *my_homedir = getenv("HOME");
http://www.die.net/doc/linux/man/man3/getenv.3.html
char *my_homedir = getenv("HOME"); if(my_homedir) my_homedir = strdup(my_homedir); else return/exit(EXIT_FAILURE);
is not safe to play with pointers which point directly to the process inherited environment space. If you are developing networked deamon that pointer could be used for some kind of exploit or nasty things. In case of environment space corruption application itself or its forked childs which inherited corrupted enviroments could crash badly.
If you want change your enviroment please use setenv/putenv
http://www.die.net/doc/linux/man/man3/setenv.3.html http://www.die.net/doc/linux/man/man3/putenv.3.html
I hope this will save your time. If not I am sorry but I am not able to read german fluently.
Cheers,