Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / argz / envz_strip.c
blob8efa5cbb5eef06581e832fd7093ee5a66429abce
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 void
15 envz_strip (char **envz,
16 size_t *envz_len)
18 char *entry = 0;
19 int len = 0;
20 int null_found = 0;
22 while((entry = argz_next(*envz, *envz_len, entry)))
24 if(!strchr(entry, '='))
26 null_found = 1;
27 len = strlen(entry) + 1;
28 /* Make sure this is not the last entry in envz. If it is, it
29 will be chopped off by the realloc anyway.*/
30 if(*envz + *envz_len != entry + len - 1)
32 memmove(entry, entry + len, *envz + *envz_len - entry - len);
34 *envz_len -= len;
37 if(null_found)
39 *envz = (char *)realloc(*envz, *envz_len);