summaryrefslogtreecommitdiff
path: root/libshouldbeinlibc/=argz.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-01-02 21:31:33 +0000
committerMiles Bader <miles@gnu.org>1996-01-02 21:31:33 +0000
commit041393523dea5a83c16271a2e032afe215445243 (patch)
tree981f0e900ffce4ad274c5a697ed5b07651e1a869 /libshouldbeinlibc/=argz.c
parent54701742e838a1fa0dc5a9f4c1caf29dfe58977c (diff)
(argz_delete): If the result is empty, free it.
Diffstat (limited to 'libshouldbeinlibc/=argz.c')
-rw-r--r--libshouldbeinlibc/=argz.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libshouldbeinlibc/=argz.c b/libshouldbeinlibc/=argz.c
index f519a434..fd90a1e2 100644
--- a/libshouldbeinlibc/=argz.c
+++ b/libshouldbeinlibc/=argz.c
@@ -131,9 +131,9 @@ argz_add (char **argz, unsigned *argz_len, char *str)
return argz_append (argz, argz_len, str, strlen (str) + 1);
}
-/* Remove ENTRY from ARGZ & ARGZ_LEN, if any. */
+/* Delete ENTRY from ARGZ & ARGZ_LEN, if any. */
void
-argz_remove (char **argz, unsigned *argz_len, char *entry)
+argz_delete (char **argz, unsigned *argz_len, char *entry)
{
if (entry)
/* Get rid of the old value for NAME. */
@@ -141,6 +141,11 @@ argz_remove (char **argz, unsigned *argz_len, char *entry)
unsigned entry_len = strlen (entry) + 1;
*argz_len -= entry_len;
bcopy (entry + entry_len, entry, *argz_len - (entry - *argz));
+ if (*argz_len == 0)
+ {
+ free (*argz);
+ *argz = 0;
+ }
}
}
@@ -159,7 +164,7 @@ argz_insert (char **argz, unsigned *argz_len, char *before, char *entry)
if (before < *argz || before >= *argz + *argz_len)
return EINVAL;
- if (before > argz)
+ if (before > *argz)
/* Make sure before is actually the beginning of an entry. */
while (before[-1])
before--;