Module Name: src
Committed By: rillig
Date: Sun Dec 6 13:51:06 UTC 2020
Modified Files:
src/usr.bin/make: var.c
Log Message:
make(1): extract FreeEnvVar from Var_Parse
To generate a diff of this commit:
cvs rdiff -u -r1.708 -r1.709 src/usr.bin/make/var.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.708 src/usr.bin/make/var.c:1.709
--- src/usr.bin/make/var.c:1.708 Sun Dec 6 10:49:02 2020
+++ src/usr.bin/make/var.c Sun Dec 6 13:51:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.708 2020/12/06 10:49:02 rillig Exp $ */
+/* $NetBSD: var.c,v 1.709 2020/12/06 13:51:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.708 2020/12/06 10:49:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.709 2020/12/06 13:51:06 rillig Exp $");
ENUM_FLAGS_RTTI_3(VarEvalFlags,
VARE_UNDEFERR, VARE_WANTRES, VARE_KEEP_DOLLAR);
@@ -3882,6 +3882,20 @@ ParseVarnameLong(
return TRUE;
}
+/* Free the environment variable now since we own it. */
+static void
+FreeEnvVar(void **out_val_freeIt, Var *v, const char *value)
+{
+ char *varValue = Buf_Destroy(&v->val, FALSE);
+ if (value == varValue)
+ *out_val_freeIt = varValue;
+ else
+ free(varValue);
+
+ free(v->name_freeIt);
+ free(v);
+}
+
/*
* Given the start of a variable expression (such as $v, $(VAR),
* ${VAR:Mpattern}), extract the variable name and value, and the modifiers,
@@ -4033,16 +4047,7 @@ Var_Parse(const char **pp, GNode *ctxt,
*pp = p;
if (v->flags & VAR_FROM_ENV) {
- /* Free the environment variable now since we own it. */
-
- char *varValue = Buf_Destroy(&v->val, FALSE);
- if (value == varValue)
- *out_val_freeIt = varValue;
- else
- free(varValue);
-
- free(v->name_freeIt);
- free(v);
+ FreeEnvVar(out_val_freeIt, v, value);
} else if (exprFlags & VEF_UNDEF) {
if (!(exprFlags & VEF_DEF)) {