diff options
Diffstat (limited to '')
-rw-r--r-- | src/var.c | 54 | ||||
-rw-r--r-- | src/var.h | 2 |
2 files changed, 18 insertions, 38 deletions
diff --git a/src/var.c b/src/var.c index fc6d367..12f2f6c 100644 --- a/src/var.c +++ b/src/var.c @@ -266,10 +266,22 @@ setvareq(char *s, int flags) if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) ckfree(vp->text); + if (((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) | + (vp->flags & VSTRFIXED)) == VUNSET) { + *vpp = vp->next; + ckfree(vp); +out_free: + if ((flags & (VTEXTFIXED|VSTACK|VNOSAVE)) == VNOSAVE) + ckfree(s); + return; + } + flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET); } else { if (flags & VNOSET) return; + if ((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) == VUNSET) + goto out_free; /* not found */ vp = ckmalloc(sizeof (*vp)); vp->next = *vpp; @@ -588,7 +600,6 @@ unsetcmd(int argc, char **argv) char **ap; int i; int flag = 0; - int ret = 0; while ((i = nextopt("vf")) != '\0') { flag = i; @@ -596,15 +607,13 @@ unsetcmd(int argc, char **argv) for (ap = argptr; *ap ; ap++) { if (flag != 'f') { - i = unsetvar(*ap); - ret |= i; - if (!(i & 2)) - continue; + unsetvar(*ap); + continue; } if (flag != 'v') unsetfunc(*ap); } - return ret & 1; + return 0; } @@ -612,38 +621,9 @@ unsetcmd(int argc, char **argv) * Unset the specified variable. */ -int -unsetvar(const char *s) +void unsetvar(const char *s) { - struct var **vpp; - struct var *vp; - int retval; - - vpp = findvar(hashvar(s), s); - vp = *vpp; - retval = 2; - if (vp) { - int flags = vp->flags; - - retval = 1; - if (flags & VREADONLY) - goto out; - if ((flags & VSTRFIXED) == 0) { - INTOFF; - if ((flags & (VTEXTFIXED|VSTACK)) == 0) - ckfree(vp->text); - *vpp = vp->next; - ckfree(vp); - INTON; - } else if (!(flags & VUNSET)) { - setvar(s, 0, 0); - vp->flags &= ~VEXPORT; - } - retval = 0; - } - -out: - return retval; + setvar(s, 0, 0); } diff --git a/src/var.h b/src/var.h index 32b0dde..2bb82b1 100644 --- a/src/var.h +++ b/src/var.h @@ -142,7 +142,7 @@ int localcmd(int, char **); void pushlocalvars(void); void poplocalvars(void); int unsetcmd(int, char **); -int unsetvar(const char *); +void unsetvar(const char *); int varcmp(const char *, const char *); static inline int varequal(const char *a, const char *b) { |