4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 20:39:33 +08:00
newlib-cygwin/newlib/libc/argz/envz_merge.c
Thomas Fitzsimmons 9b022d6db8 * libc/argz/argz_replace.c: Include buf_findstr.h.
* libc/argz/buf_findstr.c: Likewise.
	* libc/argz/envz_entry.c: Include buf_findstr.h.  Cast return
	value to (char *).
	* libc/argz/envz_get.c: Likewise.
	* libc/include/sys/unistd.h: Add getopt and getsubopt declarations.
	* libc/stdlib/Makefile.am (LIB_SOURCES): Add getsubopt.c.
	* libc/stdlib/getsubopt.3: New file.
	* libc/stdlib/getsubopt.c: New file.
	* libc/sys/linux/machine/i386/socketcall.h (__sockcall_base):
	Change esp to ebp.
2002-07-19 20:36: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((char *)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;
}