4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-30 11:00:41 +08:00
newlib-cygwin/newlib/libc/argz/envz_merge.c
Thomas Fitzsimmons b56d7e7937 * libc/argz: New directory.
* libc/argz/*: New files.
	* libc/argz/argz_add.c: New file.
	* libc/argz/argz_add_sep.c: New file.
	* libc/argz/argz_append.c: New file.
	* libc/argz/argz_count.c: New file.
	* libc/argz/argz_create.c: New file.
	* libc/argz/argz_create_sep.c: New file.
	* libc/argz/argz_delete.c: New file.
	* libc/argz/argz_extract.c: New file.
	* libc/argz/argz_insert.c: New file.
	* libc/argz/argz_next.c: New file.
	* libc/argz/argz_replace.c: New file.
	* libc/argz/argz_stringify.c: New file.
	* libc/argz/buf_findstr.c: New file.
	* libc/argz/envz_add.c: New file.
	* libc/argz/envz_entry.c: New file.
	* libc/argz/envz_get.c: New file.
	* libc/argz/envz_merge.c: New file.
	* libc/argz/envz_remove.c: New file.
	* libc/argz/envz_strip.c: New file.
	* libc/include/argz.h: New file.
	* libc/include/envz.h: New file.
	* Makefile.am (LIBC_OBJECTLISTS): Add
	libc/argz/objectlist.awk.in.
	* libc/Makefile.am (SUBDIRS): Add argz.
	(SUBLIBS): Add argz/libargz.la.
	* libc/configure.in (AC_OUTPUT): Add argz/Makefile.
	* libc/include/errno.h: Add error_t typedef.
2002-06-14 20:51:09 +00:00

57 lines
1.3 KiB
C

/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
#include <errno.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <argz.h>
#include <envz.h>
error_t
envz_merge (char **envz, size_t *envz_len, const char *envz2, size_t envz2_len, int override)
{
char *entry = NULL;
char *name_str = NULL;
char *val_str = NULL;
char *name_iter = NULL;
int retval = 0;
while((entry = argz_next(envz2, envz2_len, entry)) && !retval)
{
if (!override)
{
name_str = strdup (entry);
name_iter = strchr(name_str, '=');
if(name_iter)
*name_iter = '\0';
if(!envz_entry(*envz, *envz_len, name_str))
{
retval = argz_add(envz, envz_len, entry);
}
free(name_str);
}
else
{
name_str = strdup (entry);
name_iter = strchr(name_str, '=');
if(name_iter)
{
*name_iter = '\0';
val_str = name_iter + 1;
}
else
{
val_str = NULL;
}
retval = envz_add(envz, envz_len, name_str, val_str);
}
}
return retval;
}