--- libaitio/src/Attic/tools.c 2011/05/10 20:47:31 1.4.4.1 +++ libaitio/src/Attic/tools.c 2011/05/17 19:49:55 1.4.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.4.4.1 2011/05/10 20:47:31 misho Exp $ +* $Id: tools.c,v 1.4.4.2 2011/05/17 19:49:55 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -199,3 +199,43 @@ io_Hex2Ch(u_char *psLine, int lineLen) return str; } + +/* + * io_CopyEnv() Copy environment to new environment array; + * @oldenv = Environment array + * return: NULL error; !=NULL Allocated new environment array(must be free) +*/ +char ** +io_CopyEnv(const char **oldenv) +{ + char **newenv, **el; + register int i, num; + + if (!oldenv) + return NULL; + else + newenv = el = NULL; + + /* count items environment */ + for (i = num = 0; oldenv[i]; i++) + if (*strchr(oldenv[i], '=')) + num++; + + /* create and copy new environment */ + newenv = calloc(num + 1, sizeof(char*)); + if (!newenv) { + LOGERR; + return NULL; + } else + el = newenv; + + for (i = 0; oldenv[i]; i++) + if (*strchr(oldenv[i], '=')) { + *el = strdup(oldenv[i]); + el++; + } + *el = NULL; + + return newenv; +} +