1 /* Copyright (C) 2002 by  Red Hat, Incorporated. All rights reserved.
2  *
3  * Permission to use, copy, modify, and distribute this software
4  * is freely granted, provided that this notice is preserved.
5  */
6 
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>
13 
14 void
envz_strip(char ** envz,size_t * envz_len)15 envz_strip (char **envz,
16        size_t *envz_len)
17 {
18   char *entry = 0;
19   int len = 0;
20   int null_found = 0;
21 
22   while((entry = argz_next(*envz, *envz_len, entry)))
23     {
24       if(!strchr(entry, '='))
25         {
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)
31             {
32               memmove(entry, entry + len, *envz + *envz_len - entry - len);
33             }
34           *envz_len -= len;
35         }
36     }
37   if(null_found)
38     {
39       *envz = (char *)realloc(*envz, *envz_len);
40     }
41 }
42