env.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include <ast.h>
#include <cdt.h>
struct _venv_
{
union
{
char *ptr;
} un;
int index;
};
typedef struct _env_
{
char **env;
int count;
int extra;
int max;
int flags;
} Env_t;
#define _BLD_env 1
#include <env.h>
#define ENV_BITS 3
/*
* Compares the name portion of name=... only.
*/
{
register int c,d;
s2++;
if(c=='=')
c = 0;
if((d=*s2)=='=')
d = 0;
return(c-d);
}
{
0, -1,
sizeof(char*),
0,
0,
};
/*
* return a pointer to the environment in sorted order
* NULL is returned if there if there is nospace
*/
{
{
return(0);
}
{
}
}
/*
* add name=value pair given by <str> to <ep>
* if malloced is set, the variable will be freed when reassigned
* The environment list may become invalidated
* Returns 1 for success, 0 for failure
*/
{
return(1);
if(flags&ENV_STRDUP)
if(vp)
{
}
else
{
{
}
else
return(0);
return(0);
}
if(flags)
else
env_change();
return(1);
}
/*
* delete name from <ep>
* The environment list may become invalidated
* Returns 1 for success, 0 for if name is not present
*/
{
if(!vp)
return(0);
env_change();
return(1);
}
/*
* open up a structure to support environment variables
* initialize with environment give by <envp>
* If <extra> > 0, <extra> slots will be left at beginning of
* environment list when env_get() is involed.
* If <extra>==ENV_USABLE, then the original environ can be
* used and returned. Otherwise, a new one will be returned
*/
{
char **env;
int n=2;
return(0);
return(0);
{
while(*env++);
}
if(extra==ENV_STABLE)
{
}
else
while(--n>0)
{
vp++;
}
if(env)
{
}
return(ep);
}
/*
* close <ep> and free up all space used by it
*/
{
{
}
{
{
}
}
{
}
}