1991-04-19 05:22:06 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* putenv(3) */
|
|
|
|
/* */
|
|
|
|
/* Change or add an environment entry */
|
|
|
|
/* */
|
|
|
|
/****************************************************************/
|
|
|
|
/* origination 1987-Oct-7 T. Holm */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Path: hoptoad!pacbell!ames!ll-xn!mit-eddie!uw-beaver!ssc-vax!uvicctr!tholm
|
|
|
|
From: tholm@uvicctr.UUCP (Terrence W. Holm)
|
|
|
|
Newsgroups: comp.os.minix
|
|
|
|
Subject: putenv(3)
|
|
|
|
Message-ID: <395@uvicctr.UUCP>
|
|
|
|
Date: 5 May 88 06:40:52 GMT
|
|
|
|
Organization: University of Victoria, Victoria B.C. Canada
|
|
|
|
|
|
|
|
EFTH Minix report #2 - May 1988 - putenv(3)
|
|
|
|
|
|
|
|
This is an implementation of putenv(3) that we
|
|
|
|
wrote for Minix. Please consider this a public
|
|
|
|
domain program.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define PSIZE sizeof(char *)
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
1992-09-26 11:04:24 +02:00
|
|
|
char *strchr();
|
1991-04-19 05:22:06 +02:00
|
|
|
char *malloc();
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
* defs.h: Incorporate param.h. All users changed.
* param-no-tm.h: Change users to define TM_FILE_OVERRIDE instead.
* param.h, param-no-tm.h: Removed.
* Update copyrights in all changed files.
* dbxread.c, dwarfread.c, inflow.c, infrun.c, m2-exp.y, putenv.c,
solib.c, symtab.h, tm-umax.h, valprint.c: Lint.
* tm-convex.h, tm-hp300hpux.h, tm-merlin.h, tm-sparc.h,
xm-merlin.h: Avoid host include files in target descriptions.
* getpagesize.h: Removed, libiberty copes now.
1991-11-21 19:42:05 +01:00
|
|
|
/* int */
|
1991-04-19 05:22:06 +02:00
|
|
|
/* putenv( entry ) */
|
|
|
|
/* */
|
|
|
|
/* The "entry" should follow the form */
|
|
|
|
/* "NAME=VALUE". This routine will search the */
|
|
|
|
/* user environment for "NAME" and replace its */
|
|
|
|
/* value with "VALUE". */
|
|
|
|
/* */
|
|
|
|
/* Note that "entry" is not copied, it is used */
|
|
|
|
/* as the environment entry. This means that it */
|
|
|
|
/* must not be unallocated or otherwise modifed */
|
|
|
|
/* by the caller, unless it is replaced by a */
|
|
|
|
/* subsequent putenv(). */
|
|
|
|
/* */
|
|
|
|
/* If the name is not found in the environment, */
|
|
|
|
/* then a new vector of pointers is allocated, */
|
|
|
|
/* "entry" is put at the end and the global */
|
|
|
|
/* variable "environ" is updated. */
|
|
|
|
/* */
|
|
|
|
/* This function normally returns NULL, but -1 */
|
|
|
|
/* is returned if it can not allocate enough */
|
|
|
|
/* space using malloc(3), or "entry" does not */
|
|
|
|
/* contain a '='. */
|
|
|
|
/* */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
|
* defs.h: Incorporate param.h. All users changed.
* param-no-tm.h: Change users to define TM_FILE_OVERRIDE instead.
* param.h, param-no-tm.h: Removed.
* Update copyrights in all changed files.
* dbxread.c, dwarfread.c, inflow.c, infrun.c, m2-exp.y, putenv.c,
solib.c, symtab.h, tm-umax.h, valprint.c: Lint.
* tm-convex.h, tm-hp300hpux.h, tm-merlin.h, tm-sparc.h,
xm-merlin.h: Avoid host include files in target descriptions.
* getpagesize.h: Removed, libiberty copes now.
1991-11-21 19:42:05 +01:00
|
|
|
int
|
1991-04-19 05:22:06 +02:00
|
|
|
putenv( entry )
|
|
|
|
char *entry;
|
* defs.h: Incorporate param.h. All users changed.
* param-no-tm.h: Change users to define TM_FILE_OVERRIDE instead.
* param.h, param-no-tm.h: Removed.
* Update copyrights in all changed files.
* dbxread.c, dwarfread.c, inflow.c, infrun.c, m2-exp.y, putenv.c,
solib.c, symtab.h, tm-umax.h, valprint.c: Lint.
* tm-convex.h, tm-hp300hpux.h, tm-merlin.h, tm-sparc.h,
xm-merlin.h: Avoid host include files in target descriptions.
* getpagesize.h: Removed, libiberty copes now.
1991-11-21 19:42:05 +01:00
|
|
|
{
|
1991-04-19 05:22:06 +02:00
|
|
|
unsigned length;
|
|
|
|
unsigned size;
|
1992-01-28 03:57:37 +01:00
|
|
|
char *temp;
|
1991-04-19 05:22:06 +02:00
|
|
|
char **p;
|
|
|
|
char **new_environ;
|
|
|
|
|
|
|
|
/* Find the length of the "NAME=" */
|
|
|
|
|
1992-09-26 11:04:24 +02:00
|
|
|
temp = strchr(entry,'=');
|
1992-01-28 03:57:37 +01:00
|
|
|
if ( temp == 0 )
|
1991-04-19 05:22:06 +02:00
|
|
|
return( -1 );
|
|
|
|
|
1992-01-28 03:57:37 +01:00
|
|
|
length = (unsigned) (temp - entry + 1);
|
1991-04-19 05:22:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Scan through the environment looking for "NAME=" */
|
|
|
|
|
|
|
|
for ( p=environ; *p != 0 ; p++ )
|
|
|
|
if ( strncmp( entry, *p, length ) == 0 )
|
|
|
|
{
|
|
|
|
*p = entry;
|
1991-12-14 01:13:05 +01:00
|
|
|
return( 0 );
|
1991-04-19 05:22:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The name was not found, build a bigger environment */
|
|
|
|
|
|
|
|
size = p - environ;
|
|
|
|
|
|
|
|
new_environ = (char **) malloc( (size+2)*PSIZE );
|
|
|
|
|
1992-01-28 03:57:37 +01:00
|
|
|
if ( new_environ == (char **) NULL )
|
1991-04-19 05:22:06 +02:00
|
|
|
return( -1 );
|
|
|
|
|
* breakpoint.c, buildsym.c, c-exp.y, coffread.c, command.c,
core.c, cplus-dem.c, dbxread.c, dwarfread.c, elfread.c, environ.c,
eval.c, findvar.c, gdbtypes.c, hppabsd-tdep.c, hppahpux-tdep.c,
i386-tdep.c, ieee-float.c, infcmd.c, inflow.c, infptrace.c,
infrun.c, m2-exp.y, mipsread.c, objfiles.c, parse.c, procfs.c,
putenv.c, remote-mm.c, remote-vx.c, solib.c, sparc-tdep.c,
sparc-xdep.c, stack.c, symfile.c, symtab.c, symtab.h, target.c,
tm-i386v.h, tm-sparc.h, utils.c, valarith.c, valops.c, valprint.c,
values.c, xcoffread.c:
Remove "(void)" casts from function calls where the return value
is ignored, in accordance with GNU coding standards.
1992-07-04 05:22:08 +02:00
|
|
|
memcpy ((char *) new_environ, (char *) environ, size*PSIZE );
|
1991-04-19 05:22:06 +02:00
|
|
|
|
|
|
|
new_environ[size] = entry;
|
|
|
|
new_environ[size+1] = NULL;
|
|
|
|
|
|
|
|
environ = new_environ;
|
|
|
|
|
1991-12-14 01:13:05 +01:00
|
|
|
return(0);
|
* defs.h: Incorporate param.h. All users changed.
* param-no-tm.h: Change users to define TM_FILE_OVERRIDE instead.
* param.h, param-no-tm.h: Removed.
* Update copyrights in all changed files.
* dbxread.c, dwarfread.c, inflow.c, infrun.c, m2-exp.y, putenv.c,
solib.c, symtab.h, tm-umax.h, valprint.c: Lint.
* tm-convex.h, tm-hp300hpux.h, tm-merlin.h, tm-sparc.h,
xm-merlin.h: Avoid host include files in target descriptions.
* getpagesize.h: Removed, libiberty copes now.
1991-11-21 19:42:05 +01:00
|
|
|
}
|