fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / argz / envz_strip.c
blobe1c4610916d06f57658e9a42243b996c51b100c8
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 _DEFUN (envz_strip, (envz, envz_len),
16 char **envz _AND
17 size_t *envz_len)
19 char *entry = 0;
20 int len = 0;
21 int null_found = 0;
23 while((entry = argz_next(*envz, *envz_len, entry)))
25 if(!strchr(entry, '='))
27 null_found = 1;
28 len = strlen(entry) + 1;
29 /* Make sure this is not the last entry in envz. If it is, it
30 will be chopped off by the realloc anyway.*/
31 if(*envz + *envz_len != entry + len - 1)
33 memmove(entry, entry + len, *envz + *envz_len - entry - len);
35 *envz_len -= len;
38 if(null_found)
40 *envz = (char *)realloc(*envz, *envz_len);