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_remove(char ** envz,size_t * envz_len,const char * name)15 envz_remove (char **envz,
16        size_t *envz_len,
17        const char *name)
18 {
19   char *entry = NULL;
20   size_t len = 0;
21   entry = envz_entry (*envz, *envz_len, name);
22 
23   if (entry)
24     {
25       len = strlen(entry) + 1;
26 
27       /* Not the last entry. */
28       if (*envz + *envz_len != entry + len - 1)
29         {
30           memmove(entry, entry + len, *envz + *envz_len - entry - len);
31         }
32 
33       *envz = (char *)realloc(*envz, *envz_len - len);
34       *envz_len -= len;
35     }
36 }
37