🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #10061

Re: gestion del entorno en c

#10061
From: J.A. Gutierrez
Date: Mon, 08 Apr 2002 16:16
42 lines
2344 bytes
"V�ctor" <no@gracias.com> wrote:
: Hola, resulta que quiero ser capaz de modificar el entorno que me pasa el 
: shell a traves de:

: int main(int argc,char *argv[],char *envp[])

: que tengo en envp para asi pasarselo a los hijos ya modificado.

: La cuesti�n es que lo he intentado hacer con setenv() y tambien con 
: putenv() y ninguna de las dos me da error alguno al usarlas pero no 
: modifican la variable envp para nada, que es lo que le paso a los hijos.

putenv(3C)                                                          putenv(3C)

WARNINGS
     putenv manipulates the environment pointed to by environ, and can be used
     in conjunction with getenv.  However, envp (the third argument to main)
     is not changed.


: y c�mo usarla en mi programa. Si estoy totalmente equivocado, �alguien me 
: puede explicar como se gestiona el entorno?

	Si realmente quieres usar envp, una forma es, p.e.:

for(p1 = p2 = envp; *p1; p1++)
{
    if (strncmp(*p1, "LD_", 3) != 0) *p2++ = *p1;
}
sprintf(home,"JOME=%s", pwd->pw_dir);
*p2++ = home;
*p2 = 0;
execve( cmd, &argv[0], envp);




-- 
PGP and other useless info at      \
http://www.cps.unizar.es/~spd/      \
finger://daphne.cps.unizar.es/spd    \       Timeo Danaos et dona ferentes
ftp://ivo.cps.unizar.es/pub/          \                         (Virgilio)   
Technical Details
Message-ID: <a8sfpa$l2e$1@news.unizar.es>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.rediris.es!news.unizar.es!not-for-mail
References: <Xns91E8911342A70sounding@130.133.1.4>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,4dac1391cbff58ea
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2002-04-08 08:46:22 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news.rediris.es!news.unizar.es!not-for-mail
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: gestion del entorno en c
Date: 8 Apr 2002 16:16:41 GMT
Organization: Rank
Lines: 42
Message-ID: <a8sfpa$l2e$1@news.unizar.es>
References: <Xns91E8911342A70sounding@130.133.1.4>
NNTP-Posting-Host: daphne.cps.unizar.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.unizar.es 1018282602 21582 155.210.152.20 (8 Apr 2002 16:16:41 GMT)
X-Complaints-To: usenet@news.unizar.es
NNTP-Posting-Date: 8 Apr 2002 16:16:41 GMT
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (IRIX/6.2 (IP22))