From 10d0fb4c191ca658000ce817c0d8f0eb1ab6e55e Mon Sep 17 00:00:00 2001 From: Max Okumoto Date: Mon, 16 May 2005 17:30:24 +0000 Subject: [PATCH] Constify the result of Var_Value(). --- usr.bin/make/job.c | 4 ++-- usr.bin/make/main.c | 11 +++++++---- usr.bin/make/make.c | 20 +++++++++++--------- usr.bin/make/var.c | 15 +++++++-------- usr.bin/make/var.h | 4 ++-- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index f0f26297e6..3aa90c5724 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -38,7 +38,7 @@ * * @(#)job.c 8.2 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/job.c,v 1.75 2005/02/10 14:32:14 harti Exp $ - * $DragonFly: src/usr.bin/make/job.c,v 1.100 2005/05/16 17:29:42 okumoto Exp $ + * $DragonFly: src/usr.bin/make/job.c,v 1.101 2005/05/16 17:30:24 okumoto Exp $ */ #ifndef OLD_JOKE @@ -3327,7 +3327,7 @@ CompatInterrupt(int signo) interrupted = 0; if (curTarg != NULL && !Targ_Precious(curTarg)) { - char *file = Var_Value(TARGET, curTarg); + const char *file = Var_Value(TARGET, curTarg); if (!noExecute && eunlink(file) != -1) { printf("*** %s removed\n", file); diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 7d0205118c..f86cb72abf 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -38,7 +38,7 @@ * @(#) Copyright (c) 1988, 1989, 1990, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/main.c,v 1.118 2005/02/13 13:33:56 harti Exp $ - * $DragonFly: src/usr.bin/make/main.c,v 1.92 2005/05/16 17:29:42 okumoto Exp $ + * $DragonFly: src/usr.bin/make/main.c,v 1.93 2005/05/16 17:30:24 okumoto Exp $ */ /* @@ -661,7 +661,6 @@ main(int argc, char **argv) const char *machine_arch; const char *machine_cpu; Boolean outOfDate = TRUE; /* FALSE if all targets up to date */ - char *p; const char *pathp; const char *path; char mdpath[MAXPATHLEN]; @@ -945,8 +944,12 @@ main(int argc, char **argv) ReadMakefile(".depend"); /* Install all the flags into the MAKE envariable. */ - if (((p = Var_Value(".MAKEFLAGS", VAR_GLOBAL)) != NULL) && *p) - setenv("MAKEFLAGS", p, 1); + { + const char *p; + + if (((p = Var_Value(".MAKEFLAGS", VAR_GLOBAL)) != NULL) && *p) + setenv("MAKEFLAGS", p, 1); + } /* * For compatibility, look at the directories in the VPATH variable diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c index d762f4d2cd..07e04bdc19 100644 --- a/usr.bin/make/make.c +++ b/usr.bin/make/make.c @@ -37,7 +37,7 @@ * * @(#)make.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.bin/make/make.c,v 1.33 2005/02/04 12:38:57 harti Exp $ - * $DragonFly: src/usr.bin/make/make.c,v 1.25 2005/05/16 17:29:42 okumoto Exp $ + * $DragonFly: src/usr.bin/make/make.c,v 1.26 2005/05/16 17:30:24 okumoto Exp $ */ /* @@ -337,10 +337,10 @@ Make_HandleUse(GNode *cgn, GNode *pgn) void Make_Update(GNode *cgn) { - GNode *pgn; /* the parent node */ - char *cname; /* the child's name */ - LstNode *ln; /* Element in parents and iParents lists */ - char *cpref; + GNode *pgn; /* the parent node */ + const char *cname; /* the child's name */ + LstNode *ln; /* Element in parents and iParents lists */ + const char *cpref; cname = Var_Value(TARGET, cgn); @@ -491,8 +491,6 @@ void Make_DoAllVar(GNode *gn) { LstNode *ln; - GNode *cgn; - char *child; LST_FOREACH(ln, &gn->children) { /* @@ -508,17 +506,21 @@ Make_DoAllVar(GNode *gn) * (since .JOIN nodes don't have modification times, the * comparison is rather unfair...). */ - cgn = Lst_Datum(ln); + GNode *cgn = Lst_Datum(ln); if ((cgn->type & (OP_EXEC | OP_USE | OP_INVISIBLE)) == 0) { + const char *child; + if (OP_NOP(cgn->type)) { /* * this node is only source; use the specific * pathname for it */ child = cgn->path ? cgn->path : cgn->name; - } else + } else { child = Var_Value(TARGET, cgn); + } + Var_Append(ALLSRC, child, gn); if (gn->type & OP_JOIN) { if (cgn->made == MADE) { diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index e7beb7c968..15206673e3 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -38,7 +38,7 @@ * * @(#)var.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/var.c,v 1.83 2005/02/11 10:49:01 harti Exp $ - * $DragonFly: src/usr.bin/make/var.c,v 1.208 2005/05/16 17:29:42 okumoto Exp $ + * $DragonFly: src/usr.bin/make/var.c,v 1.209 2005/05/16 17:30:24 okumoto Exp $ */ /** @@ -1132,22 +1132,21 @@ Var_Exists(const char *name, GNode *ctxt) * Results: * The value if the variable exists, NULL if it doesn't */ -char * +const char * Var_Value(const char name[], GNode *ctxt) { Var *v; char *n; - char *p; n = VarPossiblyExpand(name, ctxt); v = VarFindAny(n, ctxt); if (v == NULL) { - p = NULL; + free(n); + return (NULL); } else { - p = Buf_Data(v->val); + free(n); + return (Buf_Data(v->val)); } - free(n); - return (p); } /** @@ -2547,7 +2546,7 @@ Var_Print(Lst *vlist, Boolean expandVars) free(v); free(value); } else { - char *value; + const char *value; value = Var_Value(name, VAR_GLOBAL); printf("%s\n", value != NULL ? value : ""); } diff --git a/usr.bin/make/var.h b/usr.bin/make/var.h index 68225647f5..c8feb7d0be 100644 --- a/usr.bin/make/var.h +++ b/usr.bin/make/var.h @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.bin/make/var.h,v 1.8 2005/02/07 16:27:19 harti Exp $ - * $DragonFly: src/usr.bin/make/var.h,v 1.37 2005/05/16 17:29:42 okumoto Exp $ + * $DragonFly: src/usr.bin/make/var.h,v 1.38 2005/05/16 17:30:24 okumoto Exp $ */ #ifndef var_h_9cccafce @@ -81,6 +81,6 @@ void Var_SetGlobal(const char *, const char *); void Var_SetEnv(const char *, struct GNode *); struct Buffer *Var_Subst(const char *, struct GNode *, Boolean); struct Buffer *Var_SubstOnly(const char *, const char *, Boolean); -char *Var_Value(const char [], struct GNode *); +const char *Var_Value(const char [], struct GNode *); #endif /* var_h_9cccafce */ -- 2.41.0