Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / argz / envz_remove.c
blob8fc9e8f1680aabd1f4e824e1edb6babd6cfe5d25
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_remove (char **envz,
16 size_t *envz_len,
17 const char *name)
19 char *entry = NULL;
20 int len = 0;
21 entry = envz_entry (*envz, *envz_len, name);
23 if (entry)
25 len = strlen(entry) + 1;
27 /* Not the last entry. */
28 if (*envz + *envz_len != entry + len - 1)
30 memmove(entry, entry + len, *envz + *envz_len - entry - len);
33 *envz = (char *)realloc(*envz, *envz_len - len);
34 *envz_len -= len;