Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / argz / envz_merge.c
blob3be7c1fbcab7daae185b8d2227594d933d64e53f
1 /* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
3 * Permission to use, copy, modify, and distribute this software
4 * is freely granted, provided that this notice is preserved.
5 */
7 #include <errno.h>
8 #include <sys/types.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <argz.h>
12 #include <envz.h>
14 error_t
15 envz_merge (char **envz,
16 size_t *envz_len,
17 const char *envz2,
18 size_t envz2_len,
19 int override)
21 char *entry = NULL;
22 char *name_str = NULL;
23 char *val_str = NULL;
24 char *name_iter = NULL;
25 int retval = 0;
27 while((entry = argz_next((char *)envz2, envz2_len, entry)) && !retval)
29 if (!override)
31 name_str = strdup (entry);
32 name_iter = strchr(name_str, '=');
33 if(name_iter)
34 *name_iter = '\0';
36 if(!envz_entry(*envz, *envz_len, name_str))
38 retval = argz_add(envz, envz_len, entry);
40 free(name_str);
42 else
44 name_str = strdup (entry);
45 name_iter = strchr(name_str, '=');
46 if(name_iter)
48 *name_iter = '\0';
49 val_str = name_iter + 1;
51 else
53 val_str = NULL;
56 retval = envz_add(envz, envz_len, name_str, val_str);
57 free(name_str);
60 return retval;