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 <argz.h>
8 #include <errno.h>
9 #include <sys/types.h>
10 #include <string.h>
11 #include <stdlib.h>
12
13 error_t
argz_delete(char ** argz,size_t * argz_len,char * entry)14 argz_delete (char **argz,
15 size_t *argz_len,
16 char *entry)
17 {
18 int len = 0;
19 char *moveto = entry;
20
21 if (entry)
22 {
23 len = strlen(entry) + 1;
24 entry += len;
25
26 memmove(moveto, entry, *argz + *argz_len - entry);
27
28 *argz_len -= len;
29
30 if(!(*argz = (char *)realloc(*argz, *argz_len)))
31 return ENOMEM;
32
33 if (*argz_len <= 0)
34 {
35 free(*argz);
36 *argz = NULL;
37 }
38 }
39 return 0;
40 }
41