--- src/usr.bin/make/var.c 2005/03/19 00:17:07 1.170 +++ src/usr.bin/make/var.c 2005/03/19 00:18:50 1.171 @@ -224,14 +224,10 @@ static char * VarPossiblyExpand(const char *name, GNode *ctxt) { Buffer *buf; - char *str; if (strchr(name, '$') != NULL) { buf = Var_Subst(NULL, name, ctxt, 0); - str = Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - - return (str); + return (Buf_Peel(buf)); } else { return estrdup(name); } @@ -471,7 +467,7 @@ Var_SetEnv(const char *name, GNode *ctxt if (v) { if ((v->flags & VAR_TO_ENV) == 0) { v->flags |= VAR_TO_ENV; - setenv(v->name, Buf_GetAll(v->val, NULL), 1); + setenv(v->name, Buf_Data(v->val), 1); } } else { Error("Cannot set environment flag on non-existant variable %s", name); @@ -515,8 +511,7 @@ Var_Append(const char *name, const char Buf_AddByte(v->val, (Byte)' '); Buf_Append(v->val, val); - DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, - (char *)Buf_GetAll(v->val, (size_t *)NULL))); + DEBUGF(VAR, ("%s:%s = %s\n", ctxt->name, n, Buf_Data(v->val))); if (v->flags & VAR_FROM_ENV) { /* @@ -587,7 +582,7 @@ Var_Value(const char *name, GNode *ctxt, free(n); *frp = NULL; if (v != NULL) { - char *p = (char *)Buf_GetAll(v->val, (size_t *)NULL); + char *p = Buf_Data(v->val); if (v->flags & VAR_FROM_ENV) { VarDestroy(v, FALSE); @@ -623,7 +618,6 @@ VarModify(const char *str, VarModifyProc Boolean addSpace; /* TRUE if need to add a space to the buffer * before adding the trimmed word */ int i; - char *result; av = brk_string(str, &ac, FALSE); @@ -633,9 +627,7 @@ VarModify(const char *str, VarModifyProc for (i = 1; i < ac; i++) addSpace = (*modProc)(av[i], addSpace, buf, datum); - result = (char *)Buf_GetAll(buf, (size_t *)NULL); - Buf_Destroy(buf, FALSE); - return (result); + return (Buf_Peel(buf)); } /*- @@ -663,7 +655,6 @@ VarSortWords(const char *str, int (*cmp) int ac; Buffer *buf; int i; - char *result; av = brk_string(str, &ac, FALSE); qsort(av + 1, ac - 1, sizeof(char *), cmp); @@ -674,9 +665,7 @@ VarSortWords(const char *str, int (*cmp) Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0')); } - result = (char *)Buf_GetAll(buf, (size_t *)NULL); - Buf_Destroy(buf, FALSE); - return (result); + return (Buf_Peel(buf)); } static int @@ -803,7 +792,6 @@ Var_Quote(const char *str) Buffer *buf; /* This should cover most shells :-( */ static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; - char *ret; buf = Buf_Init(MAKE_BSIZE); for (; *str; str++) { @@ -811,10 +799,8 @@ Var_Quote(const char *str) Buf_AddByte(buf, (Byte)'\\'); Buf_AddByte(buf, (Byte)*str); } - Buf_AddByte(buf, (Byte)'\0'); - ret = Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); - return (ret); + + return (Buf_Peel(buf)); } /*- @@ -869,15 +855,14 @@ VarExpand(Var *v, VarParser *vp) * dynamically-allocated, so it will need freeing when we * return. */ - value = (char *)Buf_GetAll(v->val, (size_t *)NULL); + value = Buf_Data(v->val); if (strchr(value, '$') == NULL) { result = strdup(value); } else { Buffer *buf; buf = Var_Subst(NULL, value, vp->ctxt, vp->err); - result = Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); + result = Buf_Peel(buf); } v->flags &= ~VAR_IN_USE; @@ -1227,8 +1212,7 @@ ParseModifier(VarParser *vp, char startc Buffer *buf; buf = Cmd_Exec(value, &error); - newStr = Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); + newStr = Buf_Peel(buf); if (error) Error(error, value); @@ -1250,8 +1234,7 @@ ParseModifier(VarParser *vp, char startc for (cp = value; *cp; cp++) Buf_AddByte(buf, (Byte)tolower(*cp)); - newStr = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); + newStr = Buf_Peel(buf); vp->ptr++; break; @@ -1276,8 +1259,7 @@ ParseModifier(VarParser *vp, char startc for (cp = value; *cp; cp++) Buf_AddByte(buf, (Byte)toupper(*cp)); - newStr = (char *)Buf_GetAll(buf, NULL); - Buf_Destroy(buf, FALSE); + newStr = Buf_Peel(buf); vp->ptr++; break; @@ -1494,7 +1476,7 @@ ParseRestEnd(VarParser *vp, Buffer *buf, * things and we sure don't put nested * invocations in them... */ - val = (char *)Buf_GetAll(v->val, NULL); + val = Buf_Data(v->val); if (vname[1] == 'D') { val = VarModify(val, VarHead, NULL); @@ -1958,7 +1940,6 @@ Var_Dump(const GNode *ctxt) LST_FOREACH(ln, &ctxt->context) { v = Lst_Datum(ln); - printf("%-16s = %s\n", v->name, - (const char *)Buf_GetAll(v->val, NULL)); + printf("%-16s = %s\n", v->name, Buf_Data(v->val)); } }